package com.hera.web.vaadin.flujo;

import static com.hera.base.util.InputData.getBooleanData;
import static com.hera.base.util.InputData.getDoubleData;
import static com.hera.base.util.InputData.getIntegerData;
import static com.hera.base.util.InputData.getObjectData;
import static com.hera.base.util.InputData.getStringData;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.hera.base.util.Constantes;
import com.hera.base.util.FiltroDTO;
import com.hera.base.util.TableCustom;
import com.hera.base.web.AbstractConfirmDialog;
import com.hera.base.web.BaseUI;
import com.hera.base.web.vaadin.component.FormButton;
import com.hera.base.web.vaadin.component.FormCheckBox;
import com.hera.base.web.vaadin.component.FormComboBox;
import com.hera.base.web.vaadin.component.FormInputDate;
import com.hera.base.web.vaadin.component.FormLabel;
import com.hera.base.web.vaadin.component.FormOptionGroup;
import com.hera.base.web.vaadin.component.FormPasswordField;
import com.hera.base.web.vaadin.component.FormRichTextArea;
import com.hera.base.web.vaadin.component.FormSlider;
import com.hera.base.web.vaadin.component.FormTable;
import com.hera.base.web.vaadin.component.FormTextArea;
import com.hera.base.web.vaadin.component.FormTextField;
import com.hera.base.web.vaadin.component.FormTwinColSelect;
import com.hera.base.web.vaadin.component.FormUpload;
import com.hera.base.web.vaadin.component.Selectable;
import com.hera.base.web.vaadin.component.SimpleSelectable;
import com.hera.base.web.vaadin.component.icon.IconAdvanced;
import com.hera.base.web.vaadin.component.icon.IconCheckBox;
import com.hera.base.web.vaadin.component.icon.IconComboBox;
import com.hera.base.web.vaadin.component.icon.IconInputDate;
import com.hera.base.web.vaadin.component.icon.IconLabel;
import com.hera.base.web.vaadin.component.icon.IconOptionGroup;
import com.hera.base.web.vaadin.component.icon.IconPasswordField;
import com.hera.base.web.vaadin.component.icon.IconRichTextArea;
import com.hera.base.web.vaadin.component.icon.IconSlider;
import com.hera.base.web.vaadin.component.icon.IconTable;
import com.hera.base.web.vaadin.component.icon.IconTextArea;
import com.hera.base.web.vaadin.component.icon.IconTextField;
import com.hera.base.web.vaadin.component.icon.IconTwinColSelect;
import com.hera.base.web.vaadin.component.icon.IconUpload;
import com.hera.base.web.vaadin.handler.ContainerDropHandler;
import com.hera.base.web.vaadin.handler.HeraDragAndDropWrapper;
import com.hera.base.web.vaadin.handler.SelectableClickListener;
import com.hera.base.web.vaadin.mantenimiento.ConditionUI;
import com.hera.base.web.vaadin.mantenimiento.DynaformStageUI;
import com.hera.base.web.vaadin.mantenimiento.FieldOptionUI;
import com.hera.base.web.vaadin.mantenimiento.ProcessFieldUI;
import com.hera.base.web.vaadin.mantenimiento.StageUserUI;
import com.hera.process.config.domain.ParameterDetail;
import com.hera.process.config.rest.delegate.ConfigDelegate;
import com.hera.process.config.rest.delegate.FormDelegate;
import com.hera.process.config.rest.delegate.WorkflowDelegate;
import com.hera.process.form.domain.Dynaform;
import com.hera.process.form.domain.DynaformField;
import com.hera.process.form.domain.DynaformFieldPK;
import com.hera.process.form.domain.FieldOption;
import com.hera.process.form.domain.FormField;
import com.hera.process.workflow.domain.Process;
import com.hera.process.workflow.domain.Stage;
import com.hera.process.workflow.domain.StageRollup;
import com.hera.process.workflow.domain.Swimlane;
import com.vaadin.annotations.AutoGenerated;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.event.LayoutEvents.LayoutClickEvent;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.Page;
import com.vaadin.server.Sizeable;
import com.vaadin.server.ThemeResource;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.AbsoluteLayout.ComponentPosition;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.BrowserFrame;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.DragAndDropWrapper;
import com.vaadin.ui.DragAndDropWrapper.DragStartMode;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.JavaScript;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.VerticalSplitPanel;
import com.vaadin.ui.Window;

public class ProcessDetailUI extends BaseUI implements ClickListener, SelectableClickListener {

	/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

	@AutoGenerated
	private VerticalLayout mainLayout;
	@AutoGenerated
	private TabSheet tabProcessDetail;
	@AutoGenerated
	private VerticalLayout vlyFormularios;
	@AutoGenerated
	private HorizontalLayout hlyFormularios;
	@AutoGenerated
	private HorizontalSplitPanel splitLeftForm;
	@AutoGenerated
	private TabSheet tabSheet_1;
	@AutoGenerated
	private VerticalLayout vtlComponentes;
	@AutoGenerated
	private VerticalSplitPanel splitRight;
	@AutoGenerated
	private VerticalLayout vlyPropsDesignForm;
	@AutoGenerated
	private Label lblPropsDesignForm;
	@AutoGenerated
	private VerticalLayout verticalLayout_1;
	@AutoGenerated
	private GridLayout gridComponents;
	@AutoGenerated
	private IconAdvanced iconAdvanced;
	@AutoGenerated
	private IconSlider iconSlider;
	@AutoGenerated
	private IconUpload iconUpload;
	@AutoGenerated
	private IconLabel iconLabel;
	@AutoGenerated
	private IconPasswordField iconPasswordField;
	@AutoGenerated
	private IconTwinColSelect iconTwinColSelect;
	@AutoGenerated
	private IconTable iconTable;
	@AutoGenerated
	private IconRichTextArea iconRichTextArea;
	@AutoGenerated
	private IconTextArea iconTextArea;
	@AutoGenerated
	private IconOptionGroup iconOptionGroup;
	@AutoGenerated
	private IconInputDate iconInputDate;
	@AutoGenerated
	private IconCheckBox iconCheckBox;
	@AutoGenerated
	private IconComboBox iComboBox;
	@AutoGenerated
	private IconTextField iTextField;
	@AutoGenerated
	private Label lbPaleta;
	@AutoGenerated
	private VerticalLayout vlyDetailForms;
	@AutoGenerated
	private HorizontalSplitPanel splitForms;
	@AutoGenerated
	private VerticalLayout vlyDesigner;
	@AutoGenerated
	private Panel pnlDesigner;
	@AutoGenerated
	private AbsoluteLayout lytContainer;
	@AutoGenerated
	private VerticalLayout vlyListaFormularios;
	@AutoGenerated
	private Button btnNuevoForm;
	@AutoGenerated
	private TableCustom tblFormularios;
	@AutoGenerated
	private VerticalLayout vlyDetalleFlujo;
	@AutoGenerated
	private HorizontalLayout hlyDetalleFlujo;
	@AutoGenerated
	private HorizontalSplitPanel splitDetalleFlujo;
	@AutoGenerated
	private VerticalLayout vlyLeftFlujo;
	@AutoGenerated
	private VerticalSplitPanel splitRigthFlow;
	@AutoGenerated
	private VerticalLayout vlyPropAdicionalFlow;
	@AutoGenerated
	private VerticalLayout vlyPropiedades;
	@AutoGenerated
	private HorizontalLayout hlyBotonera2;
	@AutoGenerated
	private Button btnAgregaStageUser;
	@AutoGenerated
	private Button btnAgregaFormStage;
	@AutoGenerated
	private HorizontalLayout hlyBotonera;
	@AutoGenerated
	private Button btnModificarStage2;
	@AutoGenerated
	private Button btnSeleccionar;
	@AutoGenerated
	private Button btnNuevoStage;
	@AutoGenerated
	private Button btnEliminarStage;
	@AutoGenerated
	private Button btnModificarStage;
	@AutoGenerated
	private TextField txtTiempo;
	@AutoGenerated
	private ComboBox cmbUnidadTiempo;
	@AutoGenerated
	private TextField txtDescripcion;
	@AutoGenerated
	private TextField txtNombre;
	@AutoGenerated
	private Label lbltitulo;
	@AutoGenerated
	private TextField txtDiagramHeight;
	@AutoGenerated
	private TextField txtDiagramWidth;
	@AutoGenerated
	private TextField txtDiagramJson;
	@AutoGenerated
	private HorizontalLayout lytFlowDesigner;
	private Process processCurrrent;
	private List<Swimlane> listSwimlane;
	private Stage stageCurrent;
	private StageRollup stageRollupCurrent;
	private DragAndDropWrapper targetWrapper;
	private Selectable selectable = null;
	private Button detailsField;

    private   AbstractComponent[] componentes;
    private boolean [][] visibilidadControles;
   
    private FieldOption valueCurrent;
    private FieldOption labelCurrent;
	Dynaform dynaform;
	DynaformField dynaformfield;
	private FormComboBox cmbComponete;
	private FormField formfield;
	
	private ProcessFieldUI processFieldUI;
	private String strOldNameStage;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 */
	public ProcessDetailUI(Process process) {
		buildMainLayout();
		setCompositionRoot(mainLayout);
		
		processCurrrent = process;
		
		listSwimlane = workflowDelegate.findSwimlaneByProcessId(processCurrrent.getIdProcess());
	}

	private static final Logger log = Logger.getLogger(ProcessDetailUI.class);
	
	@Autowired
	ConfigDelegate configDelegate;
	@Autowired
	FormDelegate formDelegate;
	@Autowired
	WorkflowDelegate workflowDelegate;
	boolean esNuevo;
	boolean esNuevoDetalle;
	com.hera.process.workflow.domain.Process mainEntity;
	
	@Override
	public void buttonClick(ClickEvent event) {
		
		System.out.println("llamando a las acciones " + event.getButton().getCaption());
		
		if(event.getButton().equals(btnEliminarStage)){
			eliminarStage();
		}else if(event.getButton().equals(btnNuevoStage)){
			guardarNuevoComponenteFlujo();
		}else if(event.getButton().equals(btnModificarStage)){
			actualizarComponenteFlujo();
		}else if(event.getButton().equals(btnModificarStage2)){
			actualizarComponente2();
		}else if(event.getButton().equals(btnSeleccionar)){
			selectComponentFlujo();
		}else 
			if(event.getButton().equals(btnNuevoForm)){
			nuevoFormulario();
		}else if(event.getButton().equals(btnGuardarForm)){
			guardarFormulario();
		}else if(event.getButton().equals(btnEliminarForm)){
			eliminarFormulario();
		}else if(event.getButton().equals(btnGuardarField)){
			actualizarField();
		}else if(event.getButton().equals(btnEliminarField)){
			eliminarField();
		}else if(event.getButton().equals(btnAgregaFormStage)){
			agregarFormStage();
		}else if(event.getButton().equals(btnAgregaStageUser)){
			agregarStageUser();
		}else if(event.getButton().equals(btnOptionField)){
			agregarFieldOption();
		}else if(event.getButton().equals(btnMostrarTablaField)){
			actualizarField();
		}else  if(event.getButton().equals(detailsField)){
			//data de tipo stagerollup
			verCondiciones((StageRollup)event.getButton().getData());			
		}
	}

	
	public void cargarFormulario() {
	
		log.info("INCIO +++++++++");
		esNuevo=true;
		mainEntity=null;
		
		//txtDiagramJson.addStyleName(Constantes.VALIDACION_CAMPOS.CAMPO_REQUERIDO);
		txtDiagramJson.addStyleName("fieldHidden");
		
		txtDescripcion.addStyleName(Constantes.VALIDACION_CAMPOS.CAMPO_REQUERIDO);
		txtNombre.addStyleName(Constantes.VALIDACION_CAMPOS.CAMPO_REQUERIDO);
		
		btnEliminarStage.setVisible(true);
		btnEliminarStage.addClickListener(this);
		btnEliminarStage.setCaption("Eliminar");
		
		btnModificarStage.setVisible(true);
		btnModificarStage.addClickListener(this);
		btnModificarStage.setCaption("Modificar");
		
		btnModificarStage2.addClickListener(this);
		
		btnNuevoStage.setVisible(true);
		btnNuevoStage.addClickListener(this);
		btnNuevoStage.setCaption("Nuevo");
		
		btnSeleccionar.setVisible(true);
		btnSeleccionar.addClickListener(this);
		btnSeleccionar.setCaption("Seleccionar");
		
		btnAgregaFormStage.addClickListener(this);
		btnAgregaStageUser.addClickListener(this);
		
		//TODO para revisar donde se inicializa esto
		btnNuevoForm.addClickListener(this);
		
		tabProcessDetail.setSizeFull();
		int windowWidth = Page.getCurrent().getBrowserWindowWidth();
		int windowHeight = Page.getCurrent().getBrowserWindowHeight();

		mainLayout.setStyleName("topMainLayout");
		
		//tabProcessDetail.setStyleName("fullMainLayout");
		
		BrowserFrame browser = new BrowserFrame("",
			    new ExternalResource("flowdesigner/designer_page.jsp"));
		browser.setId("ifrDesigner");
		browser.setWidth((windowWidth-260) + "px");
		browser.setHeight((windowHeight-105) + "px");
		lytFlowDesigner.addComponent(browser);
		splitDetalleFlujo.setWidth((windowWidth-10) + "px");
		splitDetalleFlujo.setHeight((windowHeight-70) + "px");
		
		splitDetalleFlujo.setSplitPosition((windowWidth-260), Sizeable.Unit.PIXELS);
		splitDetalleFlujo.addStyleName("splitContent");
		
		splitRigthFlow.setHeight((windowHeight-100) + "px");
		//splitRigthFlow.setWidth("100%");
		splitRigthFlow.setSplitPosition(70);
		splitRigthFlow.addStyleName("splitContent");
		
		splitLeftForm.setWidth((windowWidth-10) + "px");
		splitLeftForm.setHeight((windowHeight-70) + "px");
		splitLeftForm.setSplitPosition(80);
		splitLeftForm.addStyleName("splitContent");
		
		splitRight.setHeight((windowHeight-71) + "px");
		//splitRight.setWidth("100%");
		splitRight.setSplitPosition(50);
		splitRight.addStyleName("splitContent");
		
		splitForms.setHeight((windowHeight-70) + "px");
		splitForms.setWidth("100%");
		splitForms.setSplitPosition(20);
		splitForms.addStyleName("splitContent");
		lytContainer.addStyleName("splitContent");
		
		
		
		tblFormularios.setTitulo(" FORMULARIOS ");
		tblFormularios.setHeight("100px");
		
		tblFormularios.addColumn("name", "Nombre", 150, true, String.class);
		
		tblFormularios.construir();
		tblFormularios.addTextChangeListener(new TextChangeListener() {
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				buscarFormulario();
				
			}
		});
		
		tblFormularios.addValueChangeListener(new ValueChangeListener() {
			private static final long serialVersionUID = 1L;

			@Override
			public void valueChange(ValueChangeEvent event) {
				dynaform = (Dynaform)tblFormularios.getSelectedItem(event);
				esNuevo=(dynaform==null);
				tblFormularios.limpiarFiltro();
				if(esNuevo){
					nuevoFormulario();
				}else{
					construirMantForm();
					setearDatosFormularioDynaform(dynaform);
					//haciendo para que sea draggable
					settingUpDraggable();
					populateFormDesigner();
				}
				
				log.info("Fin Cargar Formulario Forms ");
			}
		});
		
		unsetDraggable();
	}
	
	public void mostrarControles(Object controlSeleccionado){
		int indiceControl=0;
		if(controlSeleccionado instanceof FormTextField) {
			indiceControl=0;
		}else if(controlSeleccionado instanceof FormComboBox) {
			indiceControl=1;
			FiltroDTO filtroDTO = new FiltroDTO();
			filtroDTO.addParametro("formField.idField", new Long(txtIdField.getValue()));
			
			List<FieldOption> options= formDelegate.findAllFieldOptions(filtroDTO);
			String OptionContenido= "";
			for(FieldOption option:options){
				OptionContenido+="["+option.getValue()+","+option.getLabel()+"],";
			}
			txtOptionField.setValue(OptionContenido);

			
		}else if(controlSeleccionado instanceof FormCheckBox) {
			indiceControl=2;
		}else if(controlSeleccionado instanceof FormInputDate) {
			indiceControl=3;
		}else if(controlSeleccionado instanceof FormOptionGroup) {
			indiceControl=4;
		}else if(controlSeleccionado instanceof FormTextArea) {
			indiceControl=5;
		}else if(controlSeleccionado instanceof FormRichTextArea) {
			indiceControl=6;
		}else if(controlSeleccionado instanceof FormTable) {
			indiceControl=7;
		}
		
		
		for (int i = 0; i < componentes.length; i++) {
			componentes[i].setVisible(visibilidadControles[i][indiceControl]);
		}
		
	}
	
	public void populateFormDesigner(){
		FiltroDTO filtroDTO = new FiltroDTO();
		filtroDTO.addParametro("dynaformFieldPK.idDynaform", dynaform.getIdDynaform());
		List<DynaformField> listFields = formDelegate.findAllDynaformsfield(filtroDTO);
		
		
		if(listFields != null){
			for(int i=0; i<listFields.size(); i++){
				HeraDragAndDropWrapper componentWrapper =null;
				Selectable source= createComponent(listFields.get(i));
				
				componentWrapper=new HeraDragAndDropWrapper(source);
				componentWrapper.setDragStartMode(DragStartMode.WRAPPER);
				componentWrapper.setSizeUndefined();
				
				lytContainer.addComponent(componentWrapper,"left: "+listFields.get(i).getLeft()+"px; top: "+listFields.get(i).getTop()+"px;");
				
				source.addLayoutClickListener(this);
				
			}
		}	
//		mostrarControles(null);	
	}
	
	public Selectable createComponent(DynaformField dynaformfield){
		Selectable selectablelocal = null;
		if(Constantes.FORMTYPECOMPONENT.BUTTON.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormButton();
			((FormButton)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormButton)selectablelocal).setName(dynaformfield.getField().getName());
			((FormButton)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}else if(Constantes.FORMTYPECOMPONENT.CHECKBOX.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormCheckBox();
			//((FormCheckBox)selectablelocal).setSize(formField.getLength().floatValue());
			((FormCheckBox)selectablelocal).setName(dynaformfield.getField().getName());
			((FormCheckBox)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}else if(Constantes.FORMTYPECOMPONENT.COMBOBOX.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormComboBox();
			((FormComboBox)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormComboBox)selectablelocal).setName(dynaformfield.getField().getName());
			((FormComboBox)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}else if(Constantes.FORMTYPECOMPONENT.INPUTDATE.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormInputDate();
			((FormInputDate)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormInputDate)selectablelocal).setName(dynaformfield.getField().getName());
			((FormInputDate)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}else if(Constantes.FORMTYPECOMPONENT.OPTIONGROUP.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormOptionGroup();
//			((FormOptionGroup)selectablelocal).setSize(formField.getLength().floatValue());
			((FormOptionGroup)selectablelocal).setName(dynaformfield.getField().getName());
			((FormOptionGroup)selectablelocal).setLabel(dynaformfield.getField().getLabel());
			FiltroDTO filtroDTO = new FiltroDTO();
			filtroDTO.addParametro("formField.idField", dynaformfield.getField().getIdField());
			List<FieldOption> lstFieldOptions = formDelegate.findAllFieldOptions(filtroDTO);
			if(lstFieldOptions != null){
				for(int i=0; i<lstFieldOptions.size(); i++){
					((FormOptionGroup)selectablelocal).addOption(lstFieldOptions.get(i).getLabel());
				}
			}
			
		}else if(Constantes.FORMTYPECOMPONENT.TEXTFIELD.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormTextField();
			((FormTextField)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormTextField)selectablelocal).setName(dynaformfield.getField().getName());
			((FormTextField)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}else if(Constantes.FORMTYPECOMPONENT.TEXTAREA.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormTextArea();
			((FormTextArea)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormTextArea)selectablelocal).setName(dynaformfield.getField().getName());
			((FormTextArea)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}else if(Constantes.FORMTYPECOMPONENT.RICHTEXTAREA.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormRichTextArea();
			((FormRichTextArea)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormRichTextArea)selectablelocal).setName(dynaformfield.getField().getName());
			((FormRichTextArea)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}else if(Constantes.FORMTYPECOMPONENT.TABLE.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormTable();
						
			((FormTable)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormTable)selectablelocal).setName(dynaformfield.getField().getName());
			((FormTable)selectablelocal).setLabel(dynaformfield.getField().getLabel());
			
			Long idDynaform = dynaformfield.getField().getTableForm()==null?null:dynaformfield.getField().getTableForm().getIdDynaform();
			if(idDynaform != null){
				dibujarTabla(selectablelocal, dynaformfield.getField().getTableForm().getIdDynaform(), dynaformfield);
			}
			
		}else if(Constantes.FORMTYPECOMPONENT.TWINCOLSELECT.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormTwinColSelect();
			((FormTwinColSelect)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormTwinColSelect)selectablelocal).setName(dynaformfield.getField().getName());
			((FormTwinColSelect)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}else if(Constantes.FORMTYPECOMPONENT.PASSWORD.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormPasswordField();
			((FormPasswordField)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormPasswordField)selectablelocal).setName(dynaformfield.getField().getName());
			((FormPasswordField)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}else if(Constantes.FORMTYPECOMPONENT.LABEL.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormLabel();
			((FormLabel)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormLabel)selectablelocal).setName(dynaformfield.getField().getName());
			((FormLabel)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}else if(Constantes.FORMTYPECOMPONENT.UPLOAD.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormUpload();
			((FormUpload)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormUpload)selectablelocal).setName(dynaformfield.getField().getName());
			((FormUpload)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}else if(Constantes.FORMTYPECOMPONENT.SLIDER.equals(dynaformfield.getField().getIdType())){
			selectablelocal = new FormSlider();
			((FormSlider)selectablelocal).setSize(dynaformfield.getLength().floatValue());
			((FormSlider)selectablelocal).setName(dynaformfield.getField().getName());
			((FormSlider)selectablelocal).setLabel(dynaformfield.getField().getLabel());
		}
		return selectablelocal;
	}
	
	public void dibujarTabla(Selectable selectablelocal, Long idDynaForm, DynaformField dynaformfield){
		
			
		FiltroDTO filtroDTO = new FiltroDTO();
		filtroDTO.addParametro("idDynaform", idDynaForm);
		
		List<DynaformField> listFieldTable = formDelegate.findAllDynaFormFieldByIdDynaForm(filtroDTO);
		if(listFieldTable != null && listFieldTable.size() > 0){
			for(int i=0; i<listFieldTable.size(); i++){
				((FormTable)selectablelocal).addColumnHeader(listFieldTable.get(i).getField().getLabel(), String.class, null);
				//listRows[i] = "COMPONENT" + i;
			}
			
			
			int columnSize = 0;
			HorizontalLayout hlyBotonera = new HorizontalLayout();
			hlyBotonera.setWidthUndefined();
			if(dynaformfield.getDdelete() != null  && dynaformfield.getDdelete()){
				columnSize += 52;
				Button btnDelete = new Button();
				btnDelete.setWidth("-1");
				btnDelete.setIcon(new ThemeResource("images/trash.png"));
				hlyBotonera.addComponent(btnDelete);
			}
			if(dynaformfield.getDedit() != null && dynaformfield.getDedit()){
				columnSize += 52;
				Button btnEdit = new Button();
				btnEdit.setWidth("-1");
				btnEdit.setIcon(new ThemeResource("images/edit.png"));
				hlyBotonera.addComponent(btnEdit);
			}
			if(dynaformfield.getDview() != null && dynaformfield.getDview()){
				columnSize += 52;
				Button btnView = new Button();
				btnView.setWidth("-1");
				btnView.setIcon(new ThemeResource("images/view.png"));			
				hlyBotonera.addComponent(btnView);
			}
			
			((FormTable)selectablelocal).addColumnHeader("", HorizontalLayout.class, null);
			((FormTable)selectablelocal).setColumnWidth("", columnSize + 3);
			((FormTable)selectablelocal).addSampleItem(hlyBotonera);
		}
	}
	
	public void dibujarColumnControls(FormTable selectable, boolean editable, boolean deleteable, boolean viewable){
		
		int columnSize = 0;
		HorizontalLayout hlyBotonera = new HorizontalLayout();
		hlyBotonera.setWidthUndefined();
		if(deleteable){
			columnSize += 52;
			Button btnDelete = new Button();
			btnDelete.setWidth("-1");
			btnDelete.setIcon(new ThemeResource("images/trash.png"));
			hlyBotonera.addComponent(btnDelete);
		}
		if(editable){
			columnSize += 52;
			Button btnEdit = new Button();
			btnEdit.setWidth("-1");
			btnEdit.setIcon(new ThemeResource("images/edit.png"));
			hlyBotonera.addComponent(btnEdit);
		}
		if(viewable){
			columnSize += 52;
			Button btnView = new Button();
			btnView.setWidth("-1");
			btnView.setIcon(new ThemeResource("images/view.png"));
			hlyBotonera.addComponent(btnView);
		}
		//hlyBotonera.setStyleName("toolbar");
		
		selectable.removeColumnControls();
		selectable.addColumnHeader("", HorizontalLayout.class, null);
		selectable.setColumnWidth("", columnSize + 3);
		
		selectable.removeAllItems();
		selectable.addSampleItem(hlyBotonera);
	}
	
	public void settingUpDraggable(){
		
		lytContainer = new AbsoluteLayout();
		lytContainer.setImmediate(false);
		lytContainer.setWidth("100.0%");
		lytContainer.setHeight("100.0%");
		lytContainer.setStyleName("desktop");
		targetWrapper =new DragAndDropWrapper(lytContainer);
		targetWrapper.setDropHandler(new ContainerDropHandler(lytContainer, this));
		targetWrapper.setWidth("100%");
		targetWrapper.setHeight("100%");
		pnlDesigner.setContent(targetWrapper);
	}
	
	public void unsetDraggable(){
		pnlDesigner.setContent(null);
	}

	
	private void cargarFlujo(){
		Stage stage = new Stage();
		stage.setSwimlane(listSwimlane.get(0));
		
		List<Stage> listStage = workflowDelegate.findStageByProcessId(stage);
		//Bloques del diagrama
		StringBuilder strDiagram = new StringBuilder();
		strDiagram.append("{\"blocks\":[");
		if(listStage != null){
			for(int i=0;i<listStage.size(); i++){
				strDiagram.append(listStage.get(i).getReferenceDiagram());
				if(i<listStage.size()-1){
					strDiagram.append(",");
				}
			}
		}
		strDiagram.append("]");
		
		
		//TODO
		//Revisar para hacer la discriminacion cuando se carga incialmente el 
		//select a los componentes del diagrama, la carga no deberia hacer selec para que no haga fire al obejto
		
		//List<StageRollup> listStageRollup = workflowDelegate.findStageRollupByProcessId(processCurrrent.getIdProcess());
		FiltroDTO filtroDTO = new FiltroDTO();
		filtroDTO.addParametro("idProcess", processCurrrent.getIdProcess());
		List<StageRollup> listStageRollup = workflowDelegate.findAllStageRollups(filtroDTO);
		//Conexiones del diagrama
		strDiagram.append(",\"connections\":[");
		if(listStageRollup != null){
			for(int i=0;i<listStageRollup.size(); i++){
				strDiagram.append(listStageRollup.get(i).getReferenceDiagram());
				if(i<listStageRollup.size()-1){
					strDiagram.append(",");
				}
			}
		}
		
		strDiagram.append("]}");
		txtDiagramJson.setValue(strDiagram.toString());
		txtDiagramHeight.setValue(processCurrrent.getDiagramHeight().toString());
		txtDiagramWidth.setValue(processCurrrent.getDiagramWidth().toString());
	}
	
	public void buscarFormulario() {
		buscarFormulario(null);
		//buscarFormularioCampos(null);
		
	}

	
	
	public void buscarFormulario(TextChangeEvent event) {
		log.info("inicio Buscar Process");
		//FiltroDTO filtroDTO = new FiltroDTO();
		FiltroDTO filtroDTO=tblFormularios.getFiltroDTO(event);
		filtroDTO.addParametro("idProcess", processCurrrent.getIdProcess());
		
		List<Dynaform> lstDynaForms = formDelegate.findAllDynaforms(filtroDTO);
		tblFormularios.setLstData(lstDynaForms);		
	}	
	
	public void guardarFormulario() {
		
		log.info("inicio guardarFormulario");
		if(esNuevo){
			dynaform=new Dynaform();
			obtenerDatosFormularioDynaform(dynaform);
			dynaform.setIdProcess(new Long(processCurrrent.getIdProcess().toString()));
			formDelegate.createDynaform(dynaform);
		}else{
			obtenerDatosFormularioDynaform(dynaform);
			formDelegate.updateDynaform(dynaform);
		}
		buscarFormulario();
		log.info("fin guardarFormulario");
	}
	
	public void eliminarFormulario(){
		log.info("inicio eliminarFormulario");
		formDelegate.deleteDynaform(dynaform);
		buscarFormulario();
		log.info("fin eliminarFormulario");
	}
		
	
	public void eliminarStage() {		
		log.info("inicio eliminarStage");
		
		String valorJSON = txtDiagramJson.getValue();
		String clazz = valorJSON.substring(valorJSON.indexOf("\"clazz\"")+9, valorJSON.indexOf("\"", valorJSON.indexOf("\"clazz\"")+9));
		//String idFigure = valorJSON.substring(valorJSON.indexOf("\"id\"")+6, valorJSON.indexOf("\"", valorJSON.indexOf("\"id\"")+6));
		if(Constantes.DIAGRAMCOMPONENTS.BLOCK.equalsIgnoreCase(clazz)){
			JavaScript.getCurrent().execute("document.getElementsByTagName('iframe')[1].contentWindow.deleteDiagramComponent('"+stageCurrent.getIdFigure()+"');");
			workflowDelegate.deleteStage(stageCurrent);
			stageCurrent = null;
		}else if(Constantes.DIAGRAMCOMPONENTS.CONNECTION.equalsIgnoreCase(clazz)){
			JavaScript.getCurrent().execute("document.getElementsByTagName('iframe')[1].contentWindow.deleteDiagramComponent('"+stageRollupCurrent.getIdFigure()+"');");
			workflowDelegate.deleteStageRollup(stageRollupCurrent);
			stageRollupCurrent = null;
		}
		
	}

	
	private void actualizarComponenteFlujo(){
		log.info("inicio actualizarComponenteFlujo");
		
		String valorJSON = txtDiagramJson.getValue();
		String clazz = valorJSON.substring(valorJSON.indexOf("\"clazz\"")+9, valorJSON.indexOf("\"", valorJSON.indexOf("\"clazz\"")+9));
		String idFigure = valorJSON.substring(valorJSON.indexOf("\"id\"")+6, valorJSON.indexOf("\"", valorJSON.indexOf("\"id\"")+6));
		//System.out.println(valorJSON);
		log.info("id: " + idFigure);
		log.info("clazz: " + clazz);
		if(Constantes.DIAGRAMCOMPONENTS.BLOCK.equalsIgnoreCase(clazz)){
						
			obtenerDatosFormulario(stageCurrent);
			System.out.println("nombre antiguo: " + strOldNameStage);
			if(strOldNameStage != null && !strOldNameStage.trim().equals("")){
				stageCurrent.setReferenceDiagram(valorJSON.replaceAll(">"+strOldNameStage+"<", ">"+stageCurrent.getName()+"<"));
			}else{
				stageCurrent.setReferenceDiagram(valorJSON);
			}
			
			stageCurrent = workflowDelegate.updatedStage(stageCurrent);
			//Para actualizar lo actualmente mostrado en el diagrama
			txtDiagramJson.setValue(stageCurrent.getReferenceDiagram());
			setearDatosFormulario(stageCurrent);
			JavaScript.getCurrent().execute("document.getElementsByTagName('iframe')[1].contentWindow.actualizaStage('"+stageCurrent.getName()+"');");
		}else if(Constantes.DIAGRAMCOMPONENTS.CONNECTION.equalsIgnoreCase(clazz)){
			String source = valorJSON.substring(valorJSON.indexOf("source")+9, valorJSON.indexOf("\"", valorJSON.indexOf("source")+9));
			String target = valorJSON.substring(valorJSON.indexOf("target")+9, valorJSON.indexOf("\"", valorJSON.indexOf("target")+9));
			log.info("source: " + source);
			log.info("target: " + target);
			
			
			stageRollupCurrent.setReferenceDiagram(valorJSON);
			if(source.startsWith("figure")){
				stageRollupCurrent.setIdFigureFrom(source);
			}else{
				stageRollupCurrent.setIdFigureFrom(null);
			}
			
			Stage stageFrom = new Stage();					
			stageFrom.setSwimlane(listSwimlane.get(0));
			
			stageRollupCurrent.setStageFrom(stageFrom);
			
			if(target.startsWith("figure")){
				stageRollupCurrent.setIdFigureTo(target);
			}else{
				stageRollupCurrent.setIdFigureTo(null);
			}
			workflowDelegate.updatedStageRollup(stageRollupCurrent);
		}
		
		log.info("fin actualizarComponente");
	}
	
	private void actualizarComponente2(){
		log.info("inicio actualizarComponente2");
		
		String valorJSON = txtDiagramJson.getValue();
		String clazz = valorJSON.substring(valorJSON.indexOf("\"clazz\"")+9, valorJSON.indexOf("\"", valorJSON.indexOf("\"clazz\"")+9));
		String idFigure = valorJSON.substring(valorJSON.indexOf("\"id\"")+6, valorJSON.indexOf("\"", valorJSON.indexOf("\"id\"")+6));
		//System.out.println(valorJSON);
		log.info("id: " + idFigure);
		log.info("clazz: " + clazz);
		if(Constantes.DIAGRAMCOMPONENTS.BLOCK.equalsIgnoreCase(clazz)){
			
			stageCurrent.setReferenceDiagram(valorJSON);
			//obtenerDatosFormulario(stageCurrent);
			
			workflowDelegate.updatedStage(stageCurrent);			
		}else if(Constantes.DIAGRAMCOMPONENTS.CONNECTION.equalsIgnoreCase(clazz)){
			String source = valorJSON.substring(valorJSON.indexOf("source")+9, valorJSON.indexOf("\"", valorJSON.indexOf("source")+9));
			String target = valorJSON.substring(valorJSON.indexOf("target")+9, valorJSON.indexOf("\"", valorJSON.indexOf("target")+9));
			log.info("source: " + source);
			log.info("target: " + target);
			
			
			stageRollupCurrent.setReferenceDiagram(valorJSON);
			if(source.startsWith("figure")){
				stageRollupCurrent.setIdFigureFrom(source);
			}else{
				stageRollupCurrent.setIdFigureFrom(null);
			}
			
			Stage stageFrom = new Stage();					
			stageFrom.setSwimlane(listSwimlane.get(0));
			
			stageRollupCurrent.setStageFrom(stageFrom);
			
			if(target.startsWith("figure")){
				stageRollupCurrent.setIdFigureTo(target);
			}else{
				stageRollupCurrent.setIdFigureTo(null);
			}
			workflowDelegate.updatedStageRollup(stageRollupCurrent);
		}
		log.info("fin actualizarComponente");
	}

	private Long getIdTypeNode(String nodeType){
		if(Constantes.NODETYPE.BEGIN.equalsIgnoreCase(nodeType)){
			return Constantes.NODETYPE.ID_BEGIN;
		}else if(Constantes.NODETYPE.STAGE.equalsIgnoreCase(nodeType)){
			return Constantes.NODETYPE.ID_STAGE;
		}else if(Constantes.NODETYPE.DECISION.equalsIgnoreCase(nodeType)){
			return Constantes.NODETYPE.ID_DECISION;
		}else{
			return Constantes.NODETYPE.ID_END;
		}
		
	}
	
	private void guardarNuevoComponenteFlujo() {
		
		log.info("inicio guardarNuevoComponenteFlujo");
		
			
		String valorJSON = txtDiagramJson.getValue();
		String clazz = valorJSON.substring(valorJSON.indexOf("\"clazz\"")+9, valorJSON.indexOf("\"", valorJSON.indexOf("\"clazz\"")+9));
		String idFigure = valorJSON.substring(valorJSON.indexOf("\"id\"")+6, valorJSON.indexOf("\"", valorJSON.indexOf("\"id\"")+6));
		//System.out.println(valorJSON);
		log.info("id: " + idFigure);
		log.info("clazz: " + clazz);
		if(Constantes.DIAGRAMCOMPONENTS.BLOCK.equalsIgnoreCase(clazz)){
			
			String typeNode = valorJSON.substring(valorJSON.indexOf("\"type\"")+8, valorJSON.indexOf("\"", valorJSON.indexOf("\"type\"")+8));
			log.info("typeNode: " + typeNode);
			
			stageCurrent=new Stage();
			stageCurrent.setSwimlane(listSwimlane.get(0));
			stageCurrent.setIdFigure(idFigure);
			stageCurrent.setName(idFigure);
			stageCurrent.setReferenceDiagram(valorJSON);
			stageCurrent.setIdType(getIdTypeNode(typeNode));
			
			strOldNameStage = idFigure;
			
			stageCurrent = workflowDelegate.createStage(stageCurrent);
			setearDatosFormulario(stageCurrent);
			
		}else if(Constantes.DIAGRAMCOMPONENTS.CONNECTION.equalsIgnoreCase(clazz)){
			String source = valorJSON.substring(valorJSON.indexOf("source")+9, valorJSON.indexOf("\"", valorJSON.indexOf("source")+9));
			String target = valorJSON.substring(valorJSON.indexOf("target")+9, valorJSON.indexOf("\"", valorJSON.indexOf("target")+9));
			log.info("source: " + source);
			log.info("target: " + target);
			
			StageRollup stageRollup = new StageRollup();
			stageRollup.setReferenceDiagram(valorJSON);
			stageRollup.setIdFigure(idFigure);
			stageRollup.setIdFigureFrom(source);
			stageRollup.setIdProcess(processCurrrent.getIdProcess());
			
			Stage stageFrom = new Stage();
			stageFrom.setSwimlane(listSwimlane.get(0));			
			stageRollup.setStageFrom(stageFrom);
			
			strOldNameStage = null;
			
			if(target.startsWith("figure")){
				stageRollup.setIdFigureTo(target);
			}
			workflowDelegate.createStageRollup(stageRollup);
		}		
		log.info("fin guardarNuevoComponente");
	}
	
	private void selectComponentFlujo(){
		esNuevo = false;
		log.info("seleccionando el componente...");
		String valorJSON = txtDiagramJson.getValue();
		String clazz = valorJSON.substring(valorJSON.indexOf("\"clazz\"")+9, valorJSON.indexOf("\"", valorJSON.indexOf("\"clazz\"")+9));
		
		String idFigure = valorJSON.substring(valorJSON.indexOf("\"id\"")+6, valorJSON.indexOf("\"", valorJSON.indexOf("\"id\"")+6));
		
		System.out.println("id: " + idFigure +" clazz: " + clazz);
		
		if(Constantes.DIAGRAMCOMPONENTS.BLOCK.equalsIgnoreCase(clazz)){
			stageCurrent = new Stage();
			stageCurrent.setIdFigure(idFigure);
			stageCurrent.setSwimlane(listSwimlane.get(0));
			List<Stage> listStage = workflowDelegate.findStageByProcessAndIdDiagram(stageCurrent);
			if(listStage != null && listStage.size()>0){
				stageCurrent = listStage.get(0);				
				setearDatosFormulario(stageCurrent);
				strOldNameStage = stageCurrent.getName();
				
				if(Constantes.NODETYPE.ID_DECISION.equals(stageCurrent.getIdType())){
					FiltroDTO filtroDTO = new FiltroDTO();
					filtroDTO.addParametro("stageFrom.idStage", stageCurrent.getIdStage());					
					List<StageRollup> listTransitions =  workflowDelegate.findAllStageRollups(filtroDTO);
					//crearemos la tabla
					Table tableTransitions = new Table();
					tableTransitions.addContainerProperty("Stage Destino", Component.class, null);
					tableTransitions.addContainerProperty("Default", Component.class, null);
					vlyPropAdicionalFlow.removeAllComponents();
					vlyPropAdicionalFlow.addComponent(tableTransitions);
					if(listTransitions != null){
						for(int i=0; i<listTransitions.size(); i++){
							
							detailsField = new Button(listTransitions.get(i).getStageTo().getName());
							detailsField.setData(listTransitions.get(i));
						    detailsField.addClickListener(this);
						    detailsField.addStyleName("link");
						    
						    CheckBox chkRegistry = new CheckBox();
						    chkRegistry.setImmediate(false);
						    chkRegistry.setWidth("-1px");
						    chkRegistry.setHeight("-1px");
						    //chkRegistry.setCaption("Obligatorio");
							//chkRequiredField.setValue(false);
							
							
							tableTransitions.addItem(new Object[] {
									detailsField,
									chkRegistry}, listTransitions.get(i));
						}
					}
					
				}
			}
			
		}else if(Constantes.DIAGRAMCOMPONENTS.CONNECTION.equalsIgnoreCase(clazz)){
			
			
			StageRollup stageRollupB = new StageRollup();			
			stageRollupB.setIdFigure(idFigure);
			stageRollupB.setIdProcess(processCurrrent.getIdProcess());
			List<StageRollup> listStagerollup = workflowDelegate.findStageRollupByProcessAndIdDiagram(stageRollupB);
			
			if(listStagerollup != null && listStagerollup.size()>0){
				stageRollupCurrent = listStagerollup.get(0);
			}
		}
	}
	
	
	@Override
	public void layoutClick(LayoutClickEvent event) {
		// TODO Auto-generated method stub
		//System.out.println(event.getSource());
		//Si se vuelve a seleccionar el mismo componente, no se inicializen los valores
		if(this.selectable == null || this.selectable != (Selectable)event.getSource()){
			actualizarComponente((Selectable)event.getSource());
			seleccionarComponente((Selectable)event.getSource());
			setearDatosFormField(dynaformfieldCurrent);
			mostrarControles(event.getSource());
		}
	}
	
	@Override
	public void seleccionarComponente(Selectable selectable){
		if(this.selectable != null){
			this.selectable.setStyleName("");
		}
		this.selectable = selectable;
		this.selectable.setStyleName("editable");
		//generarComponente();
		construirMantField();
	}
	
	@Override
	public void crearComponente(Selectable selectable, Float topValue, Float leftValue){
		
		formfieldCurrent = new FormField();
		formfieldCurrent.setTop(topValue.intValue());
		formfieldCurrent.setLeft(leftValue.intValue());
		formfieldCurrent.setIdProcess(dynaform.getIdProcess());
		dynaformfieldCurrent = new DynaformField();
		dynaformfieldCurrent.setTop(topValue.intValue());
		dynaformfieldCurrent.setLeft(leftValue.intValue());		
		
		if(selectable instanceof FormButton){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.BUTTON);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.BUTTON);
		}else if(selectable instanceof FormCheckBox){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.CHECKBOX);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.CHECKBOX);
		}else if(selectable instanceof FormComboBox){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.COMBOBOX);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.COMBOBOX);
			formfieldCurrent.setLength(((FormComboBox)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormComboBox)selectable).getSize().intValue());
		}else if(selectable instanceof FormInputDate){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.INPUTDATE);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.INPUTDATE);
			formfieldCurrent.setLength(((FormInputDate)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormInputDate)selectable).getSize().intValue());
		}else if(selectable instanceof FormOptionGroup){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.OPTIONGROUP);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.OPTIONGROUP);
		}else if(selectable instanceof FormTextField){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TEXTFIELD);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TEXTFIELD);
			formfieldCurrent.setLength(((FormTextField)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormTextField)selectable).getSize().intValue());
		}else if(selectable instanceof FormTextArea){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TEXTAREA);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TEXTAREA);
			formfieldCurrent.setLength(((FormTextArea)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormTextArea)selectable).getSize().intValue());
		}else if(selectable instanceof FormRichTextArea){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.RICHTEXTAREA);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.RICHTEXTAREA);
			formfieldCurrent.setLength(((FormRichTextArea)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormRichTextArea)selectable).getSize().intValue());
		}else if(selectable instanceof FormTable){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TABLE);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TABLE);
			formfieldCurrent.setLength(((FormTable)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormTable)selectable).getSize().intValue());
		}else if(selectable instanceof FormTwinColSelect){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TWINCOLSELECT);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TWINCOLSELECT);
			formfieldCurrent.setLength(((FormTwinColSelect)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormTwinColSelect)selectable).getSize().intValue());
		}else if(selectable instanceof FormPasswordField){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.PASSWORD);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.PASSWORD);
			formfieldCurrent.setLength(((FormPasswordField)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormPasswordField)selectable).getSize().intValue());
		}else if(selectable instanceof FormLabel){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.LABEL);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.LABEL);
			formfieldCurrent.setLength(((FormLabel)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormLabel)selectable).getSize().intValue());
		}else if(selectable instanceof FormUpload){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.UPLOAD);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.UPLOAD);
			formfieldCurrent.setLength(((FormUpload)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormUpload)selectable).getSize().intValue());
		}else if(selectable instanceof FormSlider){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.SLIDER);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.SLIDER);
			formfieldCurrent.setLength(((FormSlider)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormSlider)selectable).getSize().intValue());
		}		
		
		formfieldCurrent = formDelegate.createFormField(formfieldCurrent);
		dynaformfieldCurrent.setDynaformFieldPK(new DynaformFieldPK(dynaform.getIdDynaform(),formfieldCurrent.getIdField()));
		dynaformfieldCurrent.setField(formfieldCurrent);
		dynaformfieldCurrent.setDynaform(dynaform);
		dynaformfieldCurrent = formDelegate.createDynaformfield(dynaformfieldCurrent);
		
		if(selectable instanceof FormOptionGroup){
			FieldOption fieldOption = new FieldOption();
			fieldOption.setFormField(formfieldCurrent);
			//Harcode por defecto
			fieldOption.setValue("Option 1");
			fieldOption.setLabel(fieldOption.getValue());
			formDelegate.createFieldOption(fieldOption);
			((FormOptionGroup)selectable).addOption(fieldOption.getValue());
		}
		
//		setearDatosFormField(dynaformfieldCurrent.getField());
		setearDatosFormField(dynaformfieldCurrent);
		((SimpleSelectable)selectable).setName(formfieldCurrent.getName());
		((SimpleSelectable)selectable).setLabel(formfieldCurrent.getName());
		
		//buscarFormularioCampos(null);
		mostrarControles(selectable);
	}
	
	public DynaformField crearComponente(FormField formFieldCreate, Float topValue, Float leftValue){		
		
		formFieldCreate.setTop(topValue.intValue());
		formFieldCreate.setLeft(leftValue.intValue());
		formFieldCreate.setIdProcess(dynaform.getIdProcess());
		
		dynaformfieldCurrent = new DynaformField();
		dynaformfieldCurrent.setTop(topValue.intValue());
		dynaformfieldCurrent.setLeft(leftValue.intValue());
		dynaformfieldCurrent.setIdType(formFieldCreate.getIdType());
		dynaformfieldCurrent.setLength(formFieldCreate.getLength());
		
		
		/*	
		
		if(selectable instanceof FormButton){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.BUTTON);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.BUTTON);
		}else if(selectable instanceof FormCheckBox){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.CHECKBOX);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.CHECKBOX);
		}else if(selectable instanceof FormComboBox){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.COMBOBOX);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.COMBOBOX);
			formfieldCurrent.setLength(((FormComboBox)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormComboBox)selectable).getSize().intValue());
		}else if(selectable instanceof FormInputDate){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.INPUTDATE);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.INPUTDATE);
			formfieldCurrent.setLength(((FormInputDate)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormInputDate)selectable).getSize().intValue());
		}else if(selectable instanceof FormOptionGroup){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.OPTIONGROUP);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.OPTIONGROUP);
		}else if(selectable instanceof FormTextField){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TEXTFIELD);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TEXTFIELD);
			formfieldCurrent.setLength(((FormTextField)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormTextField)selectable).getSize().intValue());
		}else if(selectable instanceof FormTextArea){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TEXTAREA);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TEXTAREA);
			formfieldCurrent.setLength(((FormTextArea)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormTextArea)selectable).getSize().intValue());
		}else if(selectable instanceof FormRichTextArea){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.RICHTEXTAREA);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.RICHTEXTAREA);
			formfieldCurrent.setLength(((FormRichTextArea)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormRichTextArea)selectable).getSize().intValue());
		}else if(selectable instanceof FormTable){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TABLE);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TABLE);
			formfieldCurrent.setLength(((FormTable)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormTable)selectable).getSize().intValue());
		}else if(selectable instanceof FormTwinColSelect){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TWINCOLSELECT);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.TWINCOLSELECT);
			formfieldCurrent.setLength(((FormTwinColSelect)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormTwinColSelect)selectable).getSize().intValue());
		}else if(selectable instanceof FormPasswordField){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.PASSWORD);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.PASSWORD);
			formfieldCurrent.setLength(((FormPasswordField)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormPasswordField)selectable).getSize().intValue());
		}else if(selectable instanceof FormLabel){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.LABEL);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.LABEL);
			formfieldCurrent.setLength(((FormLabel)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormLabel)selectable).getSize().intValue());
		}else if(selectable instanceof FormUpload){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.UPLOAD);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.UPLOAD);
			formfieldCurrent.setLength(((FormUpload)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormUpload)selectable).getSize().intValue());
		}else if(selectable instanceof FormSlider){
			formfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.SLIDER);
			dynaformfieldCurrent.setIdType(Constantes.FORMTYPECOMPONENT.SLIDER);
			formfieldCurrent.setLength(((FormSlider)selectable).getSize().intValue());
			dynaformfieldCurrent.setLength(((FormSlider)selectable).getSize().intValue());
		}*/
		
		
		//formFieldCreate = formDelegate.createFormField(formFieldCreate);
		dynaformfieldCurrent.setDynaformFieldPK(new DynaformFieldPK(dynaform.getIdDynaform(),formFieldCreate.getIdField()));
		dynaformfieldCurrent.setField(formFieldCreate);
		dynaformfieldCurrent.setDynaform(dynaform);
		dynaformfieldCurrent = formDelegate.createDynaformfield(dynaformfieldCurrent);		
		
		return dynaformfieldCurrent;
	}
	
	@Override
	public void actualizarComponente(Selectable selectable, Float topValue, Float leftValue){
		
		seleccionarComponente(selectable);
		
		FiltroDTO filtroDTO1= new FiltroDTO();
		filtroDTO1.addParametro("dynaformID", dynaform.getIdDynaform());
		filtroDTO1.addParametro("nombre", selectable.getName());
		List<DynaformField> liDynaformFields = formDelegate.findAllByDynaFormField(filtroDTO1);
		if(liDynaformFields != null && liDynaformFields.size()>0){
			dynaformfieldCurrent = liDynaformFields.get(0);
			dynaformfieldCurrent.setLeft(leftValue.intValue());
			dynaformfieldCurrent.setTop(topValue.intValue());			
			
			dynaformfieldCurrent = formDelegate.updateDynaformdield(dynaformfieldCurrent);
			
			setearDatosFormField(dynaformfieldCurrent);
		}
		
	}
	
	@Override
	public void agregarComponenteAvanzado(final Float topValue, final Float leftValue){
		
		processFieldUI = new ProcessFieldUI(dynaform, new AbstractConfirmDialog() {
			@Override
			public void cancelar(Button event, Window window) {
				// TODO Auto-generated method stub				
				window.close();
			}
			
			
			@Override
			public void aceptar(Button event, Window window, Object... params) {
				// TODO Auto-generated method stub
				System.out.println(topValue);
				System.out.println(leftValue);
				if(params != null && params[0] instanceof FormField){
					FormField formField = (FormField)params[0];
					agregarField(formField, topValue, leftValue);
					
					window.close();
				}else{
					System.out.println("seleccione una fila");
				}				
			}			
		});
		
		mostrarListaCamposProceso(processFieldUI);
	}
	
	public void agregarField(FormField formField, Float topValue, Float leftValue){
		
		HeraDragAndDropWrapper componentWrapper =null;
		DynaformField dynaformField = crearComponente(formField, topValue, leftValue);
		Selectable source =  createComponent(dynaformField);
		seleccionarComponente(source);
		setearDatosFormField(dynaformField);
		//Selectable source= containerListener.createComponent((Iconifiable) component);
		componentWrapper=new HeraDragAndDropWrapper(source);
		componentWrapper.setDragStartMode(DragStartMode.WRAPPER);
		componentWrapper.setSizeUndefined();
		
		//System.out.println("left: "+(details.getMouseEvent().getClientX()-300)+"px; top: "+(details.getMouseEvent().getClientY()-35)+"px;");
		lytContainer.addComponent(componentWrapper,"left: "+leftValue+"px; top: "+topValue+"px;");
		
		source.addLayoutClickListener(this);		
	}
	
	private void mostrarListaCamposProceso(ProcessFieldUI processFieldUI){
		Window window=new Window();
		window.setStyleName("titulo-bold");		
		window.setModal(true);
		window.setResizable(false);		
		VerticalLayout layout= new VerticalLayout();
		layout.addComponent(processFieldUI);
		layout.setMargin(true);
		window.setContent(layout);
		window.setHeight("350");
		window.setWidth("300");
		UI.getCurrent().addWindow(window);
	}
	
	public void actualizarComponente(Selectable selectable){

		FiltroDTO filtroDTO1= new FiltroDTO();
		filtroDTO1.addParametro("dynaformID", dynaform.getIdDynaform());
		filtroDTO1.addParametro("nombre", selectable.getName());
		List<DynaformField> liDynaformFields = formDelegate.findAllByDynaFormField(filtroDTO1);	
		if(liDynaformFields != null && liDynaformFields.size()>0){
			dynaformfieldCurrent = liDynaformFields.get(0);
			
			//(dynaformfieldCurrent);
		}
	}
	
	public void actualizarField() {
		
		log.info("inicio actualizarField");
		
		obtenerDatosFormField(dynaformfieldCurrent);
		formDelegate.updateDynaformfieldwithFormfield(dynaformfieldCurrent);		
				
		DragAndDropWrapper controlDragAndDropWrapper = (DragAndDropWrapper)selectable.getParent();
		ComponentPosition componentPosition = lytContainer.getPosition(controlDragAndDropWrapper);
		componentPosition.setLeftValue(dynaformfieldCurrent.getLeft().floatValue());
		componentPosition.setTopValue(dynaformfieldCurrent.getTop().floatValue());		
		
		selectable.setName(dynaformfieldCurrent.getField().getName());
		
		if(selectable instanceof FormButton){
			((FormButton) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormButton) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}else if(selectable instanceof FormCheckBox){
			((FormCheckBox) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
		}else if(selectable instanceof FormComboBox){
			((FormComboBox) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormComboBox) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}else if(selectable instanceof FormInputDate){
			((FormInputDate) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormInputDate) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}else if(selectable instanceof FormOptionGroup){
			((FormOptionGroup) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormOptionGroup) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}else if(selectable instanceof FormTextField){
			((FormTextField) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormTextField) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}else if(selectable instanceof FormTextArea){
			((FormTextArea) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormTextArea) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}else if(selectable instanceof FormRichTextArea){
			((FormRichTextArea) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormRichTextArea) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}else if(selectable instanceof FormTable){
			((FormTable) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormTable) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
			dibujarTabla(selectable, dynaformfieldCurrent.getField().getTableForm().getIdDynaform(), dynaformfieldCurrent);
			
		}else if(selectable instanceof FormTwinColSelect){
			((FormTwinColSelect) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormTwinColSelect) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}else if(selectable instanceof FormPasswordField){
			((FormPasswordField) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormPasswordField) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}else if(selectable instanceof FormLabel){
			((FormLabel) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormLabel) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}else if(selectable instanceof FormUpload){
			((FormUpload) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormUpload) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}else if(selectable instanceof FormSlider){
			((FormSlider) selectable).setLabel(dynaformfieldCurrent.getField().getLabel());
			((FormSlider) selectable).setSize(dynaformfieldCurrent.getLength().floatValue());
		}
		
		log.info("fin actualizarField");
	}
	
	public void eliminarField(){
		log.info("inicio eliminarFormulario");
		
		formDelegate.deleteDynaformfield(dynaformfieldCurrent);
		
		DragAndDropWrapper controlDragAndDropWrapper = (DragAndDropWrapper)selectable.getParent();		
		lytContainer.removeComponent(controlDragAndDropWrapper);
		
		selectable = null;
		
		construirMantForm();
		setearDatosFormularioDynaform(dynaform);
		
		log.info("fin eliminarFormulario");
	}
	
	FormField formfieldCurrent = null;
	DynaformField dynaformfieldCurrent =null;
	
	//TODO aca comienza el otro panel
	VerticalLayout vlyField = null;
	TextField txtNameField = null;
	TextField txtLabelField = null;
	TextField txtDescField = null;
	TextField txtDefaultValueField = null;
	TextField txtSizeField = null;
	TextField txtLeftField = null;
	TextField txtTopField = null;
	CheckBox chkRequiredField = null;	
	TextField txtMaxLengthField = null;
	ComboBox cmbTipoTextField = null;
	TextField txtRowsField = null;
	TextField txtColsField = null;
	ComboBox cmbModoField = null;
	CheckBox chkEditarField = null;
	CheckBox chkDeleteField = null;
	CheckBox chkViewField = null;
	CheckBox chkNewField = null;
	HorizontalLayout layOptionField = null;
	TextField txtOptionField = null;
	Button btnOptionField = null;
	TextField txtIdField = null;
	ComboBox cmbFormGridField = null;
	TextField txtSequenceField = null;
	CheckBox chkIconTableField = null;
		
	HorizontalLayout hlyBotoneraField = null;
	Button btnGuardarField = null;
	Button btnEliminarField = null;
//	Button btnListarField=null;
	Button btnMostrarTablaField = null;
	
	private void limpiarLyPropsDesignForm(){
		if(vlyForm != null){
			vlyPropsDesignForm.removeComponent(vlyForm);
		}
		if(vlyField != null){
			vlyPropsDesignForm.removeComponent(vlyField);
		}
	}
	
	
	private void construirMantField(){
		limpiarLyPropsDesignForm();
		
		vlyField = new VerticalLayout();		
		vlyField.setImmediate(false);
		vlyField.setWidth("100%");
		vlyField.setHeight("-1px");
		vlyField.setMargin(false);
		
		txtIdField = new TextField();
		txtIdField.setImmediate(false);
		txtIdField.setVisible(false);
		vlyField.addComponent(txtIdField);
		
		txtNameField = new TextField();
		txtNameField.setImmediate(false);
		txtNameField.setWidth("100%");
		txtNameField.setHeight("-1px");
		txtNameField.setInputPrompt("Nombre");
		txtNameField.setMaxLength(50);
		vlyField.addComponent(txtNameField);
		
		txtLabelField = new TextField();
		txtLabelField.setImmediate(false);
		txtLabelField.setWidth("100%");
		txtLabelField.setHeight("-1px");
		txtLabelField.setInputPrompt("Etiqueta");
		txtLabelField.setMaxLength(100);
		vlyField.addComponent(txtLabelField);
		
		txtDescField = new TextField();
		txtDescField.setImmediate(false);
		txtDescField.setWidth("100%");
		txtDescField.setHeight("-1px");
		txtDescField.setInputPrompt("Descripcion");
		txtDescField.setMaxLength(200);
		vlyField.addComponent(txtDescField);
		
		txtDefaultValueField = new TextField();
		txtDefaultValueField.setImmediate(false);
		txtDefaultValueField.setWidth("100%");
		txtDefaultValueField.setHeight("-1px");
		txtDefaultValueField.setInputPrompt("Valor por Defecto");
		txtDefaultValueField.setMaxLength(100);
		vlyField.addComponent(txtDefaultValueField);
		
		txtSequenceField = new TextField();
		txtSequenceField.setImmediate(false);
		txtSequenceField.setWidth("100%");
		txtSequenceField.setHeight("-1px");
		txtSequenceField.setInputPrompt("Orden");
		txtSequenceField.setMaxLength(6);
		vlyField.addComponent(txtSequenceField);
		
		txtSizeField = new TextField();
		txtSizeField.setImmediate(false);
		txtSizeField.setWidth("100%");
		txtSizeField.setHeight("-1px");
		txtSizeField.setInputPrompt("Size");
		txtSizeField.setMaxLength(6);
		vlyField.addComponent(txtSizeField);
		
		txtLeftField = new TextField();
		txtLeftField.setImmediate(false);
		txtLeftField.setWidth("100%");
		txtLeftField.setHeight("-1px");
		txtLeftField.setInputPrompt("Left");
		txtLeftField.setMaxLength(6);
		vlyField.addComponent(txtLeftField);
		
		txtTopField = new TextField();
		txtTopField.setImmediate(false);
		txtTopField.setWidth("100%");
		txtTopField.setHeight("-1px");
		txtTopField.setInputPrompt("Top");
		txtTopField.setMaxLength(6);
		vlyField.addComponent(txtTopField);
		
		chkRequiredField = new CheckBox();
		chkRequiredField.setImmediate(false);
		chkRequiredField.setWidth("100%");
		chkRequiredField.setHeight("-1px");
		chkRequiredField.setCaption("Obligatorio");
		chkRequiredField.setValue(false);
		vlyField.addComponent(chkRequiredField);
		
		if(dynaform.getType().getIdParameterDetail().equals(Constantes.FORMTYPE.GRID)){
			chkIconTableField = new CheckBox();
			chkIconTableField.setImmediate(false);
			chkIconTableField.setWidth("100%");
			chkIconTableField.setHeight("-1px");
			chkIconTableField.setCaption("¿En Columna?");
			chkIconTableField.setValue(false);
			vlyField.addComponent(chkIconTableField);
		}
		
		txtMaxLengthField = new TextField();
		txtMaxLengthField.setImmediate(false);
		txtMaxLengthField.setWidth("100%");
		txtMaxLengthField.setHeight("-1px");
		txtMaxLengthField.setInputPrompt("MaxLength");
		txtMaxLengthField.setMaxLength(6);
		vlyField.addComponent(txtMaxLengthField);

		cmbTipoTextField = new ComboBox();
		cmbTipoTextField.setImmediate(false);
		cmbTipoTextField.setWidth("100%");
		cmbTipoTextField.setHeight("-1px");
		vlyField.addComponent(cmbTipoTextField);
		
		if(dynaformfieldCurrent != null && dynaformfieldCurrent.getField() != null){
			if(Constantes.FORMTYPECOMPONENT.TABLE.equals(dynaformfieldCurrent.getField().getIdType())){
				cmbFormGridField = new ComboBox();
				cmbFormGridField.setImmediate(true);
				cmbFormGridField.setWidth("100%");
				cmbFormGridField.setHeight("-1px");
				
				BeanItemContainer<Dynaform> type = new BeanItemContainer<Dynaform>(Dynaform.class);
				Dynaform dynaform = new Dynaform();
				dynaform.setIdProcess(processCurrrent.getIdProcess());
				type.addAll(formDelegate.findGridFormByIdProcess(dynaform));
				cmbFormGridField.setContainerDataSource(type);
				cmbFormGridField.setItemCaptionPropertyId("name");
				cmbFormGridField.setInputPrompt("Grid Form");
				cmbFormGridField.setStyleName("fieldRequired");
				cmbFormGridField.setImmediate(true);
				
				cmbFormGridField.addValueChangeListener(new ValueChangeListener() {
					private static final long serialVersionUID = 1L;

					@Override
					public void valueChange(ValueChangeEvent event) {
						// TODO Auto-generated method stub
						((FormTable)selectable).removeAllItems();
						((FormTable)selectable).clean();
						if(cmbFormGridField.getValue() != null){
							Dynaform dynaform = (Dynaform)cmbFormGridField.getValue();							
							dibujarTabla(selectable, dynaform.getIdDynaform(), dynaformfieldCurrent);							
						}
					}
				});
				
				vlyField.addComponent(cmbFormGridField);
			}
		}
		
		
		txtRowsField = new TextField();
		txtRowsField.setImmediate(false);
		txtRowsField.setWidth("100%");
		txtRowsField.setHeight("-1px");
		txtRowsField.setInputPrompt("Rows");
		txtRowsField.setMaxLength(6);
		vlyField.addComponent(txtRowsField);
		
		txtColsField = new TextField();
		txtColsField.setImmediate(false);
		txtColsField.setWidth("100%");
		txtColsField.setHeight("-1px");
		txtColsField.setInputPrompt("Cols");
		txtColsField.setMaxLength(6);
		vlyField.addComponent(txtColsField);
		
		cmbModoField = new ComboBox();
		cmbModoField.setImmediate(false);
		cmbModoField.setWidth("100%");
		cmbModoField.setHeight("-1px");
		cmbModoField.setStyleName("fieldRequired");
		BeanItemContainer<ParameterDetail> modopres = new BeanItemContainer<ParameterDetail>(ParameterDetail.class);
		ParameterDetail listsDetail = new ParameterDetail();
		listsDetail.setIdParameterDetail(Constantes.ModoField.ID);
		modopres.addAll(configDelegate.findDetailList(listsDetail));
		cmbModoField.setContainerDataSource(modopres);
		cmbModoField.setItemCaptionPropertyId("name");
		cmbModoField.setInputPrompt("Modo");
		
		vlyField.addComponent(cmbModoField);
		
		chkEditarField = new CheckBox();
		chkEditarField.setImmediate(true);
		chkEditarField.setWidth("100%");
		chkEditarField.setHeight("-1px");
		chkEditarField.setCaption("Editar");
		chkEditarField.setValue(false);
		chkEditarField.addValueChangeListener(new ValueChangeListener() {			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void valueChange(ValueChangeEvent event) {
				// TODO Auto-generated method stub
				dibujarColumnControls((FormTable)selectable, chkEditarField.getValue(), chkDeleteField.getValue(), chkViewField.getValue());
				/*if(chkEditarField.getValue()){
					((FormTable)selectable).hideColumnControls();
				}else{
					((FormTable)selectable).showColumnControls();
				}*/				
			}
		});
		
		vlyField.addComponent(chkEditarField);
		
		chkDeleteField = new CheckBox();
		chkDeleteField.setImmediate(true);
		chkDeleteField.setWidth("100%");
		chkDeleteField.setHeight("-1px");
		chkDeleteField.setCaption("Borrar");
		chkDeleteField.setValue(false);
		chkDeleteField.addValueChangeListener(new ValueChangeListener() {			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void valueChange(ValueChangeEvent event) {
				// TODO Auto-generated method stub
				dibujarColumnControls((FormTable)selectable, chkEditarField.getValue(), chkDeleteField.getValue(), chkViewField.getValue());
				/*if(chkEditarField.getValue()){
					((FormTable)selectable).hideColumnControls();
				}else{
					((FormTable)selectable).showColumnControls();
				}*/				
			}
		});
		vlyField.addComponent(chkDeleteField);
		
		chkViewField = new CheckBox();
		chkViewField.setImmediate(true);
		chkViewField.setWidth("100%");
		chkViewField.setHeight("-1px");
		chkViewField.setCaption("Ver");
		chkViewField.setValue(false);
		chkViewField.addValueChangeListener(new ValueChangeListener() {			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void valueChange(ValueChangeEvent event) {
				// TODO Auto-generated method stub
				dibujarColumnControls((FormTable)selectable, chkEditarField.getValue(), chkDeleteField.getValue(), chkViewField.getValue());
				/*if(chkEditarField.getValue()){
					((FormTable)selectable).hideColumnControls();
				}else{
					((FormTable)selectable).showColumnControls();
				}*/				
			}
		});
		vlyField.addComponent(chkViewField);
		
		chkNewField = new CheckBox();
		chkNewField.setImmediate(false);
		chkNewField.setWidth("100%");
		chkNewField.setHeight("-1px");
		chkNewField.setCaption("Nuevo");
		chkNewField.setValue(false);
		vlyField.addComponent(chkNewField);

		
		layOptionField = new HorizontalLayout();
		layOptionField.setImmediate(false);
		layOptionField.setWidth("-1px");
		layOptionField.setHeight("-1px");
		layOptionField.setMargin(false);

		// txtCodFO
		txtOptionField = new TextField();
		txtOptionField.setImmediate(false);
		txtOptionField.setEnabled(false);
		txtOptionField.setDescription("Value");
		txtOptionField.setWidth("-1px");
		txtOptionField.setHeight("-1px");
		txtOptionField.setInputPrompt("Value");
		layOptionField.addComponent(txtOptionField);
		
		// btnBuscar_FO
		btnOptionField = new Button();
		btnOptionField.setCaption("....");
		btnOptionField.setImmediate(true);
		btnOptionField.setWidth("-1px");
		btnOptionField.setHeight("-1px");
		btnOptionField.addClickListener(this);
		layOptionField.addComponent(btnOptionField);

		vlyField.addComponent(layOptionField);
		
		hlyBotoneraField = new HorizontalLayout();
		hlyBotoneraField.setImmediate(false);
		hlyBotoneraField.setWidth("-1px");
		hlyBotoneraField.setHeight("-1px");
		hlyBotoneraField.setMargin(false);
		hlyBotoneraField.setSpacing(true);
		
		btnMostrarTablaField = new Button();
		btnMostrarTablaField.setCaption("Mostrar");
		btnMostrarTablaField.setImmediate(true);
		btnMostrarTablaField.setWidth("-1px");
		btnMostrarTablaField.setHeight("23px");
		btnMostrarTablaField.addClickListener(this);
		hlyBotoneraField.addComponent(btnMostrarTablaField);
		
//		btnListarField = new Button();
//		btnListarField.setCaption("Listar");
//		btnListarField.setImmediate(true);
//		btnListarField.setWidth("-1px");
//		btnListarField.setHeight("23px");
//		btnListarField.addClickListener(this);
//		hlyBotoneraField.addComponent(btnListarField);
				
		btnGuardarField = new Button();
		btnGuardarField.setCaption("Guardar");
		btnGuardarField.setImmediate(true);
		btnGuardarField.setWidth("-1px");
		btnGuardarField.setHeight("23px");
		btnGuardarField.addClickListener(this);
		hlyBotoneraField.addComponent(btnGuardarField);
		
		btnEliminarField = new Button();
		btnEliminarField.setCaption("Eliminar");
		btnEliminarField.setImmediate(true);
		btnEliminarField.setWidth("-1px");
		btnEliminarField.setHeight("23px");
		btnEliminarField.addClickListener(this);
		hlyBotoneraField.addComponent(btnEliminarField);
		
		vlyField.addComponent(hlyBotoneraField);
		
		vlyPropsDesignForm.addComponent(vlyField);
		
		componentes = new AbstractComponent[]{txtNameField,txtLabelField,txtDescField,txtDefaultValueField,txtSizeField,
				txtLeftField,txtTopField,chkRequiredField,txtMaxLengthField,cmbTipoTextField,txtRowsField,txtColsField,
				cmbModoField,chkEditarField,chkDeleteField,chkViewField,chkNewField,btnMostrarTablaField,layOptionField,txtSequenceField};	
		visibilidadControles = new boolean[][]{
				   {true,true,true,true,true,true,true,true}, 
				   {true,true,true,true,true,true,true,true},
				   {true,true,true,true,true,true,true,true},
				   {true,true,true,true,true,true,false,false},
				   {true,true,true,true,true,true,true,true},
				   {true,true,true,true,true,true,true,true},
				   {true,true,true,true,true,true,true,true},
				   {true,true,false,true,true,true,false,true},
				   {true,false,false,false,false,true,false,false},
				   {true,false,false,false,false,false,false,false},
				   {false,false,false,false,false,true,false,false},
				   {false,false,false,false,false,true,false,false},
				   {true,true,true,true,true,true,false,true},
				   {false,false,false,false,false,false,false,true},
				   {false,false,false,false,false,false,false,true},
				   {false,false,false,false,false,false,false,true},
				   {false,false,false,false,false,false,false,true}, 
				   {true,true,true,true,true,true,true,false},
				   {false,true,false,false,true,false,false,false},
				   {true,true,true,true,true,true,true,true}
		};
	}
	
	//TODO aca comienza el otro panel
	VerticalLayout vlyForm = null;
	TextField txtNameForm = null;
	TextField txtDescForm = null;
	ComboBox cmbTipoForm = null;
	HorizontalLayout hlyBotoneraForm = null;
	Button btnGuardarForm = null;
	Button btnEliminarForm = null;
	
	public void nuevoFormulario(){
		System.out.println("nuevo Form");
		esNuevo=true;
		construirMantForm();
		if(btnEliminarForm != null){
			btnEliminarForm.setVisible(false);
		}
		
		unsetDraggable();
		tblFormularios.getTable().select(null);
	}
	
	private void construirMantForm(){
		
		limpiarLyPropsDesignForm();
		
		vlyForm = new VerticalLayout();		
		vlyForm.setImmediate(false);
		vlyForm.setWidth("100%");
		vlyForm.setHeight("-1px");
		vlyForm.setMargin(false);
		
		txtNameForm = new TextField();
		txtNameForm.setImmediate(false);
		txtNameForm.setWidth("100%");
		txtNameForm.setHeight("-1px");
		txtNameForm.setInputPrompt("Nombre");
		txtNameForm.setMaxLength(100);
		vlyForm.addComponent(txtNameForm);
		
		txtDescForm = new TextField();
		txtDescForm.setImmediate(false);
		txtDescForm.setWidth("100%");
		txtDescForm.setHeight("-1px");
		txtDescForm.setInputPrompt("Descripcion");
		txtDescForm.setMaxLength(200);
		vlyForm.addComponent(txtDescForm);
		
		cmbTipoForm = new ComboBox();
		cmbTipoForm.setImmediate(false);
		cmbTipoForm.setWidth("100%");
		cmbTipoForm.setHeight("-1px");
		
		BeanItemContainer<ParameterDetail> modopres = new BeanItemContainer<ParameterDetail>(ParameterDetail.class);
		ParameterDetail listsDetail = new ParameterDetail();
		listsDetail.setIdParameterDetail(Constantes.TipoFormulario.ID);
		modopres.addAll(configDelegate.findDetailList(listsDetail));
		cmbTipoForm.setContainerDataSource(modopres);
		cmbTipoForm.setItemCaptionPropertyId("name");
		cmbTipoForm.setInputPrompt("Tipo Formulario");
		
		vlyForm.addComponent(cmbTipoForm);
		
		hlyBotoneraForm = new HorizontalLayout();
		hlyBotoneraForm.setImmediate(false);
		hlyBotoneraForm.setWidth("-1px");
		hlyBotoneraForm.setHeight("-1px");
		hlyBotoneraForm.setMargin(false);
		hlyBotoneraForm.setSpacing(true);
				
		btnGuardarForm = new Button();
		btnGuardarForm.setCaption("Guardar");
		btnGuardarForm.setImmediate(true);
		btnGuardarForm.setWidth("-1px");
		btnGuardarForm.setHeight("23px");
		btnGuardarForm.addClickListener(this);
		hlyBotoneraForm.addComponent(btnGuardarForm);
		
		btnEliminarForm = new Button();
		btnEliminarForm.setCaption("Eliminar");
		btnEliminarForm.setImmediate(true);
		btnEliminarForm.setWidth("-1px");
		btnEliminarForm.setHeight("23px");
		btnEliminarForm.addClickListener(this);
		hlyBotoneraForm.addComponent(btnEliminarForm);
		
		vlyForm.addComponent(hlyBotoneraForm);
		
		vlyPropsDesignForm.addComponent(vlyForm);
	}
	
	private void agregarFormStage(){
		Window window=new Window();
		window.setStyleName("titulo-bold");
		
		window.setModal(true);
		window.setResizable(false);
		
		window.setCaption("Lista de Formularios para el Stage: " + stageCurrent.getName());
		
		DynaformStageUI dynaformStageUI =new DynaformStageUI(stageCurrent, processCurrrent);
		VerticalLayout layout=new VerticalLayout();
		layout.addComponent(dynaformStageUI);
		layout.setMargin(true);
		window.setContent(layout);
		window.setHeight("300");
		window.setWidth("500");
		UI.getCurrent().addWindow(window);
	}
	
	private void agregarFieldOption(){
		Window window=new Window();
		window.setStyleName("titulo-bold");
		
		window.setModal(true);
		window.setResizable(false);
//		window.setCaption("Lista de formularios para el FieldOption : " +valueCurrent.getValue());
		FieldOptionUI fieldOptionUI= new FieldOptionUI(new Long(txtIdField.getValue()));
		VerticalLayout layout= new VerticalLayout();
		layout.addComponent(fieldOptionUI);
		layout.setMargin(true);
		window.setContent(layout);
		window.setHeight("500");
		window.setWidth("500");
		UI.getCurrent().addWindow(window);
		
		
	}
	
	
	private void agregarStageUser(){
		Window window=new Window();
		window.setStyleName("titulo-bold");
		
		window.setModal(true);
		window.setResizable(false);
		
		window.setCaption("Lista de Usuarios para el Stage: " + stageCurrent.getName());
		
		StageUserUI stageUserUI =new StageUserUI(stageCurrent, processCurrrent);
		VerticalLayout layout=new VerticalLayout();
		layout.addComponent(stageUserUI);
		layout.setMargin(true);
		window.setContent(layout);
		window.setHeight("300");
		window.setWidth("500");
		UI.getCurrent().addWindow(window);
	}	
	
	private void verCondiciones(StageRollup stagerollup){
		Window window=new Window();
		window.setStyleName("titulo-bold");
		
		window.setModal(true);
		window.setResizable(false);
		
		window.setCaption("Lista de Condiciones");
		
		ConditionUI conditionUI =new ConditionUI(stagerollup, processCurrrent);
		VerticalLayout layout=new VerticalLayout();
		layout.addComponent(conditionUI);
		layout.setMargin(true);
		window.setContent(layout);
		window.setHeight("350");
		window.setWidth("550");
		UI.getCurrent().addWindow(window);
	}	

	@Override
	protected void postConstruct() {
		cargarFormulario();
		buscarFormulario();
		cargarFlujo();
	}

	private void setearDatosFormulario(Stage stage) {
		txtNombre.setValue(stage.getName()==null?"":stage.getName());
		txtDescripcion.setValue(stage.getDescription()==null?"":stage.getDescription());
		txtTiempo.setValue(stage.getTimeAmout()==null?"0.0":stage.getTimeAmout().toString());			
	}
	
	private void obtenerDatosFormulario(Stage stage) {			
		stage.setName(getStringData(txtNombre,"Nombre"));
		stage.setDescription(getStringData(txtDescripcion,"Descripcion"));
		stage.setTimeAmout(getDoubleData(txtTiempo,"Tiempo"));			
	}
	
	private void setearDatosFormularioDynaform(Dynaform dynaform) {			
		txtNameForm.setValue(dynaform.getName()==null?"":dynaform.getName());
		txtDescForm.setValue(dynaform.getDescription()==null?"":dynaform.getDescription());
		cmbTipoForm.setValue(dynaform.getType());
	}
	
	private void obtenerDatosFormularioDynaform(Dynaform dynaform) {			
		dynaform.setName(getStringData(txtNameForm,"Nombre"));
		dynaform.setDescription(getStringData(txtDescForm,"Descripcion"));
		dynaform.setType(getObjectData(cmbTipoForm, ParameterDetail.class, "Tipo"));
	}

	private void setearDatosFormField(DynaformField dynaformfield) {		
		txtIdField.setValue(""+dynaformfield.getField().getIdField());
		txtNameField.setValue(dynaformfield.getField().getName()==null?"":dynaformfield.getField().getName());
		txtLabelField.setValue(dynaformfield.getField().getLabel()==null?"":dynaformfield.getField().getLabel());
		txtDescField.setValue(dynaformfield.getField().getDescription()==null?"":dynaformfield.getField().getDescription());
//		txtDefaultValueField.setValue(dynaformField.getField().getDefaultValue()==null?"":dynaformField.getField().getDefaultValue());
		txtSizeField.setValue(dynaformfield.getLength()==null?"":dynaformfield.getLength().toString());
		txtLeftField.setValue(dynaformfield.getLeft()==null?"":dynaformfield.getLeft().toString());
		txtTopField.setValue(dynaformfield.getTop()==null?"":dynaformfield.getTop().toString());
		txtSequenceField.setValue(dynaformfield.getSequence()==null?"":dynaformfield.getSequence().toString());
		if(Constantes.FORMTYPECOMPONENT.TABLE.equals(dynaformfieldCurrent.getField().getIdType())){
			chkRequiredField.setValue(dynaformfield.getField().getRequired());
			chkDeleteField.setValue(dynaformfield.getDdelete()==null?false:dynaformfield.getDdelete());
			chkEditarField.setValue(dynaformfield.getDedit()==null?false:dynaformfield.getDedit());
			chkViewField.setValue(dynaformfield.getDview()==null?false:dynaformfield.getDview());
			chkNewField.setValue(dynaformfield.getDnew()==null?false:dynaformfield.getDnew());
			if(dynaformfield.getField().getTableForm() != null){
				cmbFormGridField.setValue(dynaformfield.getField().getTableForm());
			}
		}else if(Constantes.FORMTYPECOMPONENT.TEXTFIELD.equals(dynaformfield.getField().getIdType())){
			txtMaxLengthField.setValue(dynaformfield.getField().getMaxLength()==null?"":dynaformfield.getField().getMaxLength().toString());
			chkRequiredField.setValue(dynaformfield.getField().getRequired());
			cmbModoField.setValue(dynaformfield.getMode());
		}else if(Constantes.FORMTYPECOMPONENT.COMBOBOX.equals(dynaformfield.getField().getIdType())){
			chkRequiredField.setValue(dynaformfield.getField().getRequired());
			cmbModoField.setValue(dynaformfield.getMode());
		}else if(Constantes.FORMTYPECOMPONENT.CHECKBOX.equals(dynaformfield.getField().getIdType())){
			//chkRequiredField.setValue(dynaformfield.getField().getRequired());
			cmbModoField.setValue(dynaformfield.getMode());
		}else if(Constantes.FORMTYPECOMPONENT.INPUTDATE.equals(dynaformfield.getField().getIdType())){
			chkRequiredField.setValue(dynaformfield.getField().getRequired());
			cmbModoField.setValue(dynaformfield.getMode());
		}else if(Constantes.FORMTYPECOMPONENT.OPTIONGROUP.equals(dynaformfield.getField().getIdType())){
			chkRequiredField.setValue(dynaformfield.getField().getRequired());
			cmbModoField.setValue(dynaformfield.getMode());
		}else if(Constantes.FORMTYPECOMPONENT.TEXTAREA.equals(dynaformfield.getField().getIdType())){
			txtMaxLengthField.setValue(dynaformfield.getField().getMaxLength()==null?"":dynaformfield.getField().getMaxLength().toString());
			chkRequiredField.setValue(dynaformfield.getField().getRequired());
			txtRowsField.setValue(dynaformfield.getNumberRows()==null?"":dynaformfield.getNumberRows().toString());
			txtColsField.setValue(dynaformfield.getNumberCols()==null?"":dynaformfield.getNumberCols().toString());
			cmbModoField.setValue(dynaformfield.getMode());
		}
		
		if(dynaform.getType().getIdParameterDetail().equals(Constantes.FORMTYPE.GRID)){
			chkIconTableField.setValue(dynaformfield.getIconifiable());
		}
	}
//	

	
	private void obtenerDatosFormField(DynaformField dynaformField) {			
		dynaformField.getField().setName(getStringData(txtNameField,"Nombre"));
		dynaformField.getField().setLabel(getStringData(txtLabelField,"Label"));
		dynaformField.getField().setDescription(getStringData(txtDescField,"Descripción"));
//		dynaformField.getField().setDefaultValue(getStringData(txtDefaultValueField,"Valor por Defecto"));
		dynaformField.setLength(getIntegerData(txtSizeField,"Size"));
		dynaformField.setLeft(getIntegerData(txtLeftField,"Left"));
		dynaformField.setTop(getIntegerData(txtTopField,"Top"));
		dynaformField.setSequence(getIntegerData(txtSequenceField,"Orden"));
		if(Constantes.FORMTYPECOMPONENT.TABLE.equals(dynaformField.getField().getIdType())){
			dynaformField.getField().setRequired(getBooleanData(chkRequiredField,"Obligatorio"));
			dynaformField.setDdelete(getBooleanData(chkDeleteField,"Borrar"));
			dynaformField.setDedit(getBooleanData(chkEditarField,"Editar"));
			dynaformField.setDnew(getBooleanData(chkNewField,"Nuevo"));
			dynaformField.setDview(getBooleanData(chkViewField,"Ver"));
			dynaformField.getField().setTableForm(getObjectData(cmbFormGridField, Dynaform.class, "Formulario Tabla"));			
		}else if(Constantes.FORMTYPECOMPONENT.TEXTFIELD.equals(dynaformField.getField().getIdType())){
			dynaformField.getField().setMaxLength(getIntegerData(txtMaxLengthField,"MaxLength"));
			dynaformField.getField().setRequired(getBooleanData(chkRequiredField,"Obligatorio"));
			dynaformField.setMode(getObjectData(cmbModoField, ParameterDetail.class, "Modo"));
		}else if(Constantes.FORMTYPECOMPONENT.COMBOBOX.equals(dynaformField.getField().getIdType())){			
			dynaformField.getField().setRequired(getBooleanData(chkRequiredField,"Obligatorio"));
			dynaformField.setMode(getObjectData(cmbModoField, ParameterDetail.class, "Modo"));
		}else if(Constantes.FORMTYPECOMPONENT.CHECKBOX.equals(dynaformField.getField().getIdType())){			
			//dynaformField.getField().setRequired(getBooleanData(chkRequiredField,"Obligatorio"));
			dynaformField.setMode(getObjectData(cmbModoField, ParameterDetail.class, "Modo"));
		}else if(Constantes.FORMTYPECOMPONENT.INPUTDATE.equals(dynaformField.getField().getIdType())){			
			dynaformField.getField().setRequired(getBooleanData(chkRequiredField,"Obligatorio"));
			dynaformField.setMode(getObjectData(cmbModoField, ParameterDetail.class, "Modo"));
		}else if(Constantes.FORMTYPECOMPONENT.OPTIONGROUP.equals(dynaformField.getField().getIdType())){			
			dynaformField.getField().setRequired(getBooleanData(chkRequiredField,"Obligatorio"));
			dynaformField.setMode(getObjectData(cmbModoField, ParameterDetail.class, "Modo"));
		}else if(Constantes.FORMTYPECOMPONENT.TEXTAREA.equals(dynaformField.getField().getIdType())){			
			dynaformField.getField().setRequired(getBooleanData(chkRequiredField,"Obligatorio"));
			dynaformField.getField().setMaxLength(getIntegerData(txtMaxLengthField,"MaxLength"));
			dynaformField.setNumberRows(getIntegerData(txtRowsField,"Rows"));
			dynaformField.setNumberCols(getIntegerData(txtColsField,"Cols"));
			dynaformField.setMode(getObjectData(cmbModoField, ParameterDetail.class, "Modo"));
		}
		
		if(dynaform.getType().getIdParameterDetail().equals(Constantes.FORMTYPE.GRID)){
			dynaformField.setIconifiable(getBooleanData(chkIconTableField,"En Columna"));
		}
	
	}
	
	
@AutoGenerated
private VerticalLayout buildMainLayout() {
	// common part: create layout
	mainLayout = new VerticalLayout();
	mainLayout.setImmediate(false);
	mainLayout.setWidth("-1px");
	mainLayout.setHeight("-1px");
	mainLayout.setMargin(false);
	
	// top-level component properties
	setWidth("-1px");
	setHeight("-1px");
	
	// tabProcessDetail
	tabProcessDetail = buildTabProcessDetail();
	mainLayout.addComponent(tabProcessDetail);
	mainLayout.setExpandRatio(tabProcessDetail, 1.0f);
	
	return mainLayout;
}


@AutoGenerated
private TabSheet buildTabProcessDetail() {
	// common part: create layout
	tabProcessDetail = new TabSheet();
	tabProcessDetail.setImmediate(true);
	tabProcessDetail.setWidth("100.0%");
	tabProcessDetail.setHeight("-1px");
	
	// vlyDetalleFlujo
	vlyDetalleFlujo = buildVlyDetalleFlujo();
	tabProcessDetail.addTab(vlyDetalleFlujo, "Flujo", null);
	
	// vlyFormularios
	vlyFormularios = buildVlyFormularios();
	tabProcessDetail.addTab(vlyFormularios, "Formularios", null);
	
	return tabProcessDetail;
}


@AutoGenerated
private VerticalLayout buildVlyDetalleFlujo() {
	// common part: create layout
	vlyDetalleFlujo = new VerticalLayout();
	vlyDetalleFlujo.setImmediate(false);
	vlyDetalleFlujo.setWidth("-1px");
	vlyDetalleFlujo.setHeight("-1px");
	vlyDetalleFlujo.setMargin(false);
	vlyDetalleFlujo.setSpacing(true);
	
	// hlyDetalleFlujo
	hlyDetalleFlujo = buildHlyDetalleFlujo();
	vlyDetalleFlujo.addComponent(hlyDetalleFlujo);
	
	return vlyDetalleFlujo;
}


@AutoGenerated
private HorizontalLayout buildHlyDetalleFlujo() {
	// common part: create layout
	hlyDetalleFlujo = new HorizontalLayout();
	hlyDetalleFlujo.setImmediate(false);
	hlyDetalleFlujo.setWidth("-1px");
	hlyDetalleFlujo.setHeight("-1px");
	hlyDetalleFlujo.setMargin(false);
	hlyDetalleFlujo.setSpacing(true);
	
	// splitDetalleFlujo
	splitDetalleFlujo = buildSplitDetalleFlujo();
	hlyDetalleFlujo.addComponent(splitDetalleFlujo);
	
	return hlyDetalleFlujo;
}


@AutoGenerated
private HorizontalSplitPanel buildSplitDetalleFlujo() {
	// common part: create layout
	splitDetalleFlujo = new HorizontalSplitPanel();
	splitDetalleFlujo.setImmediate(false);
	splitDetalleFlujo.setWidth("400px");
	splitDetalleFlujo.setHeight("200px");
	
	// lytFlowDesigner
	lytFlowDesigner = new HorizontalLayout();
	lytFlowDesigner.setImmediate(false);
	lytFlowDesigner.setWidth("-1px");
	lytFlowDesigner.setHeight("-1px");
	lytFlowDesigner.setMargin(false);
	splitDetalleFlujo.addComponent(lytFlowDesigner);
	
	// vlyLeftFlujo
	vlyLeftFlujo = buildVlyLeftFlujo();
	splitDetalleFlujo.addComponent(vlyLeftFlujo);
	
	return splitDetalleFlujo;
}


@AutoGenerated
private VerticalLayout buildVlyLeftFlujo() {
	// common part: create layout
	vlyLeftFlujo = new VerticalLayout();
	vlyLeftFlujo.setImmediate(false);
	vlyLeftFlujo.setWidth("-1px");
	vlyLeftFlujo.setHeight("-1px");
	vlyLeftFlujo.setMargin(false);
	vlyLeftFlujo.setSpacing(true);
	
	// splitRigthFlow
	splitRigthFlow = buildSplitRigthFlow();
	vlyLeftFlujo.addComponent(splitRigthFlow);
	
	return vlyLeftFlujo;
}


@AutoGenerated
private VerticalSplitPanel buildSplitRigthFlow() {
	// common part: create layout
	splitRigthFlow = new VerticalSplitPanel();
	splitRigthFlow.setImmediate(false);
	splitRigthFlow.setWidth("100.0%");
	splitRigthFlow.setHeight("200px");
	
	// vlyPropiedades
	vlyPropiedades = buildVlyPropiedades();
	splitRigthFlow.addComponent(vlyPropiedades);
	
	// vlyPropAdicionalFlow
	vlyPropAdicionalFlow = new VerticalLayout();
	vlyPropAdicionalFlow.setImmediate(false);
	vlyPropAdicionalFlow.setWidth("-1px");
	vlyPropAdicionalFlow.setHeight("-1px");
	vlyPropAdicionalFlow.setMargin(false);
	splitRigthFlow.addComponent(vlyPropAdicionalFlow);
	
	return splitRigthFlow;
}


@AutoGenerated
private VerticalLayout buildVlyPropiedades() {
	// common part: create layout
	vlyPropiedades = new VerticalLayout();
	vlyPropiedades.setImmediate(false);
	vlyPropiedades.setWidth("250px");
	vlyPropiedades.setHeight("-1px");
	vlyPropiedades.setMargin(false);
	
	// txtDiagramJson
	txtDiagramJson = new TextField();
	txtDiagramJson.setImmediate(false);
	txtDiagramJson.setWidth("197px");
	txtDiagramJson.setHeight("-1px");
	txtDiagramJson.setInputPrompt("JSON");
	vlyPropiedades.addComponent(txtDiagramJson);
	
	// txtDiagramWidth
	txtDiagramWidth = new TextField();
	txtDiagramWidth.setStyleName("fieldHidden");
	txtDiagramWidth.setImmediate(false);
	txtDiagramWidth.setWidth("197px");
	txtDiagramWidth.setHeight("-1px");
	vlyPropiedades.addComponent(txtDiagramWidth);
	
	// txtDiagramHeight
	txtDiagramHeight = new TextField();
	txtDiagramHeight.setStyleName("fieldHidden");
	txtDiagramHeight.setImmediate(false);
	txtDiagramHeight.setWidth("197px");
	txtDiagramHeight.setHeight("-1px");
	txtDiagramHeight.setInputPrompt("JSON");
	vlyPropiedades.addComponent(txtDiagramHeight);
	
	// lbltitulo
	lbltitulo = new Label();
	lbltitulo.setImmediate(false);
	lbltitulo.setWidth("-1px");
	lbltitulo.setHeight("-1px");
	lbltitulo.setValue("DETALLE");
	vlyPropiedades.addComponent(lbltitulo);
	
	// txtNombre
	txtNombre = new TextField();
	txtNombre.setImmediate(false);
	txtNombre.setWidth("197px");
	txtNombre.setHeight("-1px");
	txtNombre.setInputPrompt("Nombre");
	txtNombre.setMaxLength(50);
	vlyPropiedades.addComponent(txtNombre);
	
	// txtDescripcion
	txtDescripcion = new TextField();
	txtDescripcion.setImmediate(false);
	txtDescripcion.setWidth("197px");
	txtDescripcion.setHeight("-1px");
	txtDescripcion.setInputPrompt("Descripcion");
	txtDescripcion.setMaxLength(200);
	vlyPropiedades.addComponent(txtDescripcion);
	
	// cmbUnidadTiempo
	cmbUnidadTiempo = new ComboBox();
	cmbUnidadTiempo.setImmediate(false);
	cmbUnidadTiempo.setWidth("-1px");
	cmbUnidadTiempo.setHeight("-1px");
	vlyPropiedades.addComponent(cmbUnidadTiempo);
	
	// txtTiempo
	txtTiempo = new TextField();
	txtTiempo.setImmediate(false);
	txtTiempo.setWidth("197px");
	txtTiempo.setHeight("-1px");
	txtTiempo.setInputPrompt("Tiempo");
	txtTiempo.setMaxLength(20);
	vlyPropiedades.addComponent(txtTiempo);
	
	// hlyBotonera
	hlyBotonera = buildHlyBotonera();
	vlyPropiedades.addComponent(hlyBotonera);
	
	// hlyBotonera2
	hlyBotonera2 = buildHlyBotonera2();
	vlyPropiedades.addComponent(hlyBotonera2);
	
	return vlyPropiedades;
}


@AutoGenerated
private HorizontalLayout buildHlyBotonera() {
	// common part: create layout
	hlyBotonera = new HorizontalLayout();
	hlyBotonera.setImmediate(false);
	hlyBotonera.setWidth("-1px");
	hlyBotonera.setHeight("-1px");
	hlyBotonera.setMargin(false);
	hlyBotonera.setSpacing(true);
	
	// btnModificarStage
	btnModificarStage = new Button();
	btnModificarStage.setCaption("Modificar");
	btnModificarStage.setImmediate(true);
	btnModificarStage.setWidth("-1px");
	btnModificarStage.setHeight("23px");
	hlyBotonera.addComponent(btnModificarStage);
	
	// btnEliminarStage
	btnEliminarStage = new Button();
	btnEliminarStage.setCaption("Eliminar");
	btnEliminarStage.setImmediate(true);
	btnEliminarStage.setWidth("-1px");
	btnEliminarStage.setHeight("-1px");
	hlyBotonera.addComponent(btnEliminarStage);
	
	// btnNuevoStage
	btnNuevoStage = new Button();
	btnNuevoStage.setCaption("Nuevo");
	btnNuevoStage.setImmediate(true);
	btnNuevoStage.setWidth("-1px");
	btnNuevoStage.setHeight("-1px");
	hlyBotonera.addComponent(btnNuevoStage);
	
	
	
	return hlyBotonera;
}


@AutoGenerated
private HorizontalLayout buildHlyBotonera2() {
	// common part: create layout
	hlyBotonera2 = new HorizontalLayout();
	hlyBotonera2.setImmediate(false);
	hlyBotonera2.setWidth("-1px");
	hlyBotonera2.setHeight("-1px");
	hlyBotonera2.setMargin(false);
	
	// btnAgregaFormStage
	btnAgregaFormStage = new Button();
	btnAgregaFormStage.setCaption("+");
	btnAgregaFormStage.setImmediate(true);
	btnAgregaFormStage.setWidth("-1px");
	btnAgregaFormStage.setHeight("-1px");
	hlyBotonera2.addComponent(btnAgregaFormStage);
	
	// btnAgregaStageUser
	btnAgregaStageUser = new Button();
	btnAgregaStageUser.setCaption("+");
	btnAgregaStageUser.setImmediate(true);
	btnAgregaStageUser.setWidth("-1px");
	btnAgregaStageUser.setHeight("-1px");
	hlyBotonera2.addComponent(btnAgregaStageUser);
	
	// btnSeleccionar
	btnSeleccionar = new Button();
	btnSeleccionar.setCaption("Select");
	btnSeleccionar.setImmediate(true);
	btnSeleccionar.setWidth("-1px");
	btnSeleccionar.setHeight("-1px");
	hlyBotonera2.addComponent(btnSeleccionar);
	
	// btnModificarStage2
	btnModificarStage2 = new Button();
	btnModificarStage2.setCaption("+");
	btnModificarStage2.setImmediate(true);
	btnModificarStage2.setWidth("-1px");
	btnModificarStage2.setHeight("-1px");
	hlyBotonera2.addComponent(btnModificarStage2);
	
	return hlyBotonera2;
}


@AutoGenerated
private VerticalLayout buildVlyFormularios() {
	// common part: create layout
	vlyFormularios = new VerticalLayout();
	vlyFormularios.setImmediate(false);
	vlyFormularios.setWidth("-1px");
	vlyFormularios.setHeight("-1px");
	vlyFormularios.setMargin(false);
	
	// hlyFormularios
	hlyFormularios = buildHlyFormularios();
	vlyFormularios.addComponent(hlyFormularios);
	
	return vlyFormularios;
}


@AutoGenerated
private HorizontalLayout buildHlyFormularios() {
	// common part: create layout
	hlyFormularios = new HorizontalLayout();
	hlyFormularios.setImmediate(false);
	hlyFormularios.setWidth("-1px");
	hlyFormularios.setHeight("-1px");
	hlyFormularios.setMargin(false);
	hlyFormularios.setSpacing(true);
	
	// splitLeftForm
	splitLeftForm = buildSplitLeftForm();
	hlyFormularios.addComponent(splitLeftForm);
	
	return hlyFormularios;
}


@AutoGenerated
private HorizontalSplitPanel buildSplitLeftForm() {
	// common part: create layout
	splitLeftForm = new HorizontalSplitPanel();
	splitLeftForm.setImmediate(false);
	splitLeftForm.setWidth("400px");
	splitLeftForm.setHeight("200px");
	
	// vlyDetailForms
	vlyDetailForms = buildVlyDetailForms();
	splitLeftForm.addComponent(vlyDetailForms);
	
	// tabSheet_1
	tabSheet_1 = buildTabSheet_1();
	splitLeftForm.addComponent(tabSheet_1);
	
	return splitLeftForm;
}


@AutoGenerated
private VerticalLayout buildVlyDetailForms() {
	// common part: create layout
	vlyDetailForms = new VerticalLayout();
	vlyDetailForms.setImmediate(false);
	vlyDetailForms.setWidth("100.0%");
	vlyDetailForms.setHeight("100.0%");
	vlyDetailForms.setMargin(false);
	
	// splitForms
	splitForms = buildSplitForms();
	vlyDetailForms.addComponent(splitForms);
	
	return vlyDetailForms;
}


@AutoGenerated
private HorizontalSplitPanel buildSplitForms() {
	// common part: create layout
	splitForms = new HorizontalSplitPanel();
	splitForms.setImmediate(false);
	splitForms.setWidth("200px");
	splitForms.setHeight("200px");
	
	// vlyListaFormularios
	vlyListaFormularios = buildVlyListaFormularios();
	splitForms.addComponent(vlyListaFormularios);
	
	// vlyDesigner
	vlyDesigner = buildVlyDesigner();
	splitForms.addComponent(vlyDesigner);
	
	return splitForms;
}


@AutoGenerated
private VerticalLayout buildVlyListaFormularios() {
	// common part: create layout
	vlyListaFormularios = new VerticalLayout();
	vlyListaFormularios.setImmediate(false);
	vlyListaFormularios.setWidth("-1px");
	vlyListaFormularios.setHeight("-1px");
	vlyListaFormularios.setMargin(false);
	vlyListaFormularios.setSpacing(true);
	
	// tblFormularios
	tblFormularios = new TableCustom();
	tblFormularios.setImmediate(false);
	tblFormularios.setWidth("-1px");
	tblFormularios.setHeight("-1px");
	vlyListaFormularios.addComponent(tblFormularios);
	
	// btnNuevoForm
	btnNuevoForm = new Button();
	btnNuevoForm.setCaption("+");
	btnNuevoForm.setImmediate(true);
	btnNuevoForm.setWidth("-1px");
	btnNuevoForm.setHeight("-1px");
	vlyListaFormularios.addComponent(btnNuevoForm);
	
	return vlyListaFormularios;
}


@AutoGenerated
private VerticalLayout buildVlyDesigner() {
	// common part: create layout
	vlyDesigner = new VerticalLayout();
	vlyDesigner.setImmediate(false);
	vlyDesigner.setWidth("100.0%");
	vlyDesigner.setHeight("100.0%");
	vlyDesigner.setMargin(false);
	
	// pnlDesigner
	pnlDesigner = buildPnlDesigner();
	vlyDesigner.addComponent(pnlDesigner);
	
	return vlyDesigner;
}


@AutoGenerated
private Panel buildPnlDesigner() {
	// common part: create layout
	pnlDesigner = new Panel();
	pnlDesigner.setImmediate(false);
	pnlDesigner.setWidth("100.0%");
	pnlDesigner.setHeight("100.0%");
	
	// lytContainer
	lytContainer = new AbsoluteLayout();
	lytContainer.setImmediate(false);
	lytContainer.setWidth("100.0%");
	lytContainer.setHeight("100.0%");
	pnlDesigner.setContent(lytContainer);
	
	return pnlDesigner;
}


@AutoGenerated
private TabSheet buildTabSheet_1() {
	// common part: create layout
	tabSheet_1 = new TabSheet();
	tabSheet_1.setImmediate(true);
	tabSheet_1.setWidth("-1px");
	tabSheet_1.setHeight("-1px");
	tabSheet_1.hideTabs(true);
	
	// vtlComponentes
	vtlComponentes = buildVtlComponentes();
	tabSheet_1.addTab(vtlComponentes, "Componentes", null);
	
	return tabSheet_1;
}


@AutoGenerated
private VerticalLayout buildVtlComponentes() {
	// common part: create layout
	vtlComponentes = new VerticalLayout();
	vtlComponentes.setImmediate(false);
	vtlComponentes.setWidth("-1px");
	vtlComponentes.setHeight("-1px");
	vtlComponentes.setMargin(false);
	vtlComponentes.setSpacing(true);
	
	// splitRight
	splitRight = buildSplitRight();
	vtlComponentes.addComponent(splitRight);
	
	return vtlComponentes;
}


@AutoGenerated
private VerticalSplitPanel buildSplitRight() {
	// common part: create layout
	splitRight = new VerticalSplitPanel();
	splitRight.setImmediate(false);
	splitRight.setWidth("100.0%");
	splitRight.setHeight("200px");
	
	// verticalLayout_1
	verticalLayout_1 = buildVerticalLayout_1();
	splitRight.addComponent(verticalLayout_1);
	
	// vlyPropsDesignForm
	vlyPropsDesignForm = buildVlyPropsDesignForm();
	splitRight.addComponent(vlyPropsDesignForm);
	
	return splitRight;
}


@AutoGenerated
private VerticalLayout buildVerticalLayout_1() {
	// common part: create layout
	verticalLayout_1 = new VerticalLayout();
	verticalLayout_1.setStyleName("toolbar");
	verticalLayout_1.setImmediate(false);
	verticalLayout_1.setWidth("250px");
	verticalLayout_1.setHeight("-1px");
	verticalLayout_1.setMargin(false);
	verticalLayout_1.setSpacing(true);
	
	// lbPaleta
	lbPaleta = new Label();
	lbPaleta.setImmediate(false);
	lbPaleta.setWidth("-1px");
	lbPaleta.setHeight("-1px");
	lbPaleta.setValue("Componentes");
	verticalLayout_1.addComponent(lbPaleta);
	
	// gridComponents
	gridComponents = buildGridComponents();
	verticalLayout_1.addComponent(gridComponents);
	
	return verticalLayout_1;
}


@AutoGenerated
private GridLayout buildGridComponents() {
	// common part: create layout
	gridComponents = new GridLayout();
	gridComponents.setImmediate(false);
	gridComponents.setWidth("-1px");
	gridComponents.setHeight("-1px");
	gridComponents.setMargin(false);
	gridComponents.setColumns(3);
	gridComponents.setRows(5);
	
	// iTextField
	iTextField = new IconTextField();
	iTextField.setImmediate(false);
	iTextField.setWidth("50px");
	iTextField.setHeight("50px");
	gridComponents.addComponent(iTextField, 0, 0);
	
	// iComboBox
	iComboBox = new IconComboBox();
	iComboBox.setImmediate(false);
	iComboBox.setWidth("50px");
	iComboBox.setHeight("50px");
	gridComponents.addComponent(iComboBox, 1, 0);
	
	// iconCheckBox
	iconCheckBox = new IconCheckBox();
	iconCheckBox.setImmediate(false);
	iconCheckBox.setWidth("50px");
	iconCheckBox.setHeight("50px");
	gridComponents.addComponent(iconCheckBox, 2, 0);
	
	// iconInputDate
	iconInputDate = new IconInputDate();
	iconInputDate.setImmediate(false);
	iconInputDate.setWidth("50px");
	iconInputDate.setHeight("50px");
	gridComponents.addComponent(iconInputDate, 0, 1);
	
	// iconOptionGroup
	iconOptionGroup = new IconOptionGroup();
	iconOptionGroup.setImmediate(false);
	iconOptionGroup.setWidth("50px");
	iconOptionGroup.setHeight("50px");
	gridComponents.addComponent(iconOptionGroup, 1, 1);
	
	// iconTextArea
	iconTextArea = new IconTextArea();
	iconTextArea.setImmediate(false);
	iconTextArea.setWidth("50px");
	iconTextArea.setHeight("50px");
	gridComponents.addComponent(iconTextArea, 2, 1);
	
	// iconRichTextArea
	iconRichTextArea = new IconRichTextArea();
	iconRichTextArea.setImmediate(false);
	iconRichTextArea.setWidth("50px");
	iconRichTextArea.setHeight("50px");
	gridComponents.addComponent(iconRichTextArea, 0, 2);
	
	// iconTable
	iconTable = new IconTable();
	iconTable.setImmediate(false);
	iconTable.setWidth("50px");
	iconTable.setHeight("50px");
	gridComponents.addComponent(iconTable, 1, 2);
	
	// iconTwinColSelect
	iconTwinColSelect = new IconTwinColSelect();
	iconTwinColSelect.setImmediate(false);
	iconTwinColSelect.setWidth("50px");
	iconTwinColSelect.setHeight("50px");
	gridComponents.addComponent(iconTwinColSelect, 2, 2);
	
	// iconPasswordField
	iconPasswordField = new IconPasswordField();
	iconPasswordField.setImmediate(false);
	iconPasswordField.setWidth("50px");
	iconPasswordField.setHeight("50px");
	gridComponents.addComponent(iconPasswordField, 0, 3);
	
	// iconLabel
	iconLabel = new IconLabel();
	iconLabel.setImmediate(false);
	iconLabel.setWidth("50px");
	iconLabel.setHeight("50px");
	gridComponents.addComponent(iconLabel, 1, 3);
	
	// iconUpload
	iconUpload = new IconUpload();
	iconUpload.setImmediate(false);
	iconUpload.setWidth("50px");
	iconUpload.setHeight("50px");
	gridComponents.addComponent(iconUpload, 2, 3);
	
	// iconSlider
	iconSlider = new IconSlider();
	iconSlider.setImmediate(false);
	iconSlider.setWidth("50px");
	iconSlider.setHeight("50px");
	gridComponents.addComponent(iconSlider, 0, 4);
	
	// iconAdvanced
	iconAdvanced = new IconAdvanced();
	iconAdvanced.setImmediate(false);
	iconAdvanced.setWidth("50px");
	iconAdvanced.setHeight("50px");
	gridComponents.addComponent(iconAdvanced, 1, 4);
	
	return gridComponents;
}


@AutoGenerated
private VerticalLayout buildVlyPropsDesignForm() {
	// common part: create layout
	vlyPropsDesignForm = new VerticalLayout();
	vlyPropsDesignForm.setImmediate(false);
	vlyPropsDesignForm.setWidth("-1px");
	vlyPropsDesignForm.setHeight("-1px");
	vlyPropsDesignForm.setMargin(false);
	vlyPropsDesignForm.setSpacing(true);
	
	// lblPropsDesignForm
	lblPropsDesignForm = new Label();
	lblPropsDesignForm.setImmediate(false);
	lblPropsDesignForm.setWidth("-1px");
	lblPropsDesignForm.setHeight("-1px");
	lblPropsDesignForm.setValue("Propiedades");
	vlyPropsDesignForm.addComponent(lblPropsDesignForm);
	
	return vlyPropsDesignForm;
}
	
	
}
